Period reference
Friendly interface for time span manipulations.
Classes
timeless.period.Period(start: Union[str, Datetime], end: Union[str, Datetime], freq: str = 'days', step: int = 1, parse_kwargs: dict = dict())
Bases: list
Timeless time span.
Source code in timeless/period.py
Functions
append(item: Datetime) -> None
Append a datetime instance to the end of the period.
Parameters:
-
item
(
Datetime
) –Datetime instance to append.
Raises:
-
ValueError
–Only Datetime instances allowed.
-
TypeError
–Periods cannot have duplicate items.
Source code in timeless/period.py
duration() -> float
property
Total duration of the period in seconds.
Returns:
-
float
–total seconds in the time span.
eq(other: Period) -> bool
ge(other: Period) -> bool
get_duration() -> float
gt(other: Period) -> bool
insert(index: SupportsIndex, item: Datetime) -> None
Insert a datetime instance at the given index.
Parameters:
-
index
(
int
) –List index to insert at.
-
item
(
Datetime
) –Datetime instance to insert.
Raises:
-
ValueError
–Only Datetime instances allowed.
-
TypeError
–Periods cannot have duplicate items.
Source code in timeless/period.py
le(other: Period) -> bool
lt(other: Period) -> bool
shift(years: int = 0, months: int = 0, days: int = 0, hours: int = 0, minutes: int = 0, seconds: int = 0, microseconds: int = 0) -> Period
Sum or subtract a timedelta from the period.
Currently only supports relativedelta.
Parameters:
-
years
(
int, optional
) –years delta, by default 0
-
months
(
int, optional
) –months delta, by default 0
-
days
(
int, optional
) –days delta, by default 0
-
hours
(
int, optional
) –hours delta, by default 0
-
minutes
(
int, optional
) –minutes delta, by default 0
-
seconds
(
int, optional
) –seconds delta, by default 0
-
microseconds
(
int, optional
) –microseconds delta, by default 0
Returns:
-
Period
–New period with the given timedelta added.
Source code in timeless/period.py
timeless.period.Periodkwargs
Bases: TypedDict
Types for Period class.
Functions
timeless.period.get_current_month(zone: str = 'UTC', **period_kwargs: Unpack[Periodkwargs]) -> Period
Get current month as a Period in days.
You can set Period Kwargs to change time freq and step.
Parameters:
-
zone
(
str, optional
) –Timezone, by default "UTC"
Returns:
-
Period
–Month time span.
Source code in timeless/period.py
timeless.period.get_current_week(week_first_day: str = 'monday', zone: str = 'UTC', **period_kwargs: Unpack[Periodkwargs]) -> Period
Get current week as a Period in days.
You can set Period Kwargs to change time freq and step.
Parameters:
-
week_first_day
(
str, optional
) –Start day of the week, by default "monday"
-
zone
(
str, optional
) –Timezone, by default "UTC"
Returns:
-
Period
–Week time span.
Source code in timeless/period.py
timeless.period.get_month(day: Datetime, **period_kwargs: Unpack[Periodkwargs]) -> Period
Given a datetime object, get relative month as a Period in days.
You can set Period Kwargs to change time freq and step.
Parameters:
-
day
(
Datetime
) –Reference Datetime.
Returns:
-
Period
–Month time span.
Source code in timeless/period.py
timeless.period.get_week(day: Datetime, week_first_day: str = 'monday', **period_kwargs: Unpack[Periodkwargs]) -> Period
Given a datetime object, get relative week as a Period in days.
You can set Period Kwargs to change time freq and step.
Parameters:
-
day
(
Datetime
) –Reference Datetime.
-
week_first_day
(
str, optional
) –Start day of the week, by default "monday"
Returns:
-
Period
–Week time span.