API Reference#
regta_period#
AbstractPeriod#
- class regta_period.AbstractPeriod#
Bases:
ABC
The minimum interface every period object has.
- abstract get_interval(dt: datetime) timedelta #
Get time to the next moment as timedelta since passed moment.
- Parameters:
dt (datetime) – Current moment (\(t\))
- Returns:
Interval to the next moment (\(f(t)\))
- Return type:
timedelta
- abstract get_next(dt: datetime) datetime #
Get the next moment since passed moment.
- Parameters:
dt (datetime) – Current moment (\(t\))
- Returns:
The next moment (\(t + f(t)\))
- Return type:
datetime
- abstract property is_timezone_in_use: bool#
If timezone is specified, return True, else False.
Period#
- class regta_period.Period(days: int = 0, hours: int = 0, minutes: int = 0, seconds: int = 0, milliseconds: int = 0, time: Optional[str] = None, timezone: Optional[Union[tzinfo, str, int, float]] = None, weekdays: Optional[Iterable[Weekdays]] = None)#
Bases:
AbstractPeriod
The core logic of this module.
- Parameters:
days (int) – Amount of days for the regular offset.
hours (int) – Amount of hours for the regular offset.
minutes (int) – Amount of minutes for the regular offset.
seconds (int) – Amount of seconds for the regular offset.
milliseconds (int) – Amount of milliseconds for the regular offset.
time (str) – Exact time of moments (time offset). Format: “HH:MM” or “HH:MM:SS”.
timezone (Union[tzinfo, str, int, float]) – Time zone for exact time. If
str
, then it will be converted intotzinfo
viazoneinfo.ZoneInfo
. Ifint
orfloat
, then it will be used directly as an offset for the time offset.weekdays (Iterable[Weekdays]) – Time windows of weekdays.
- every(n: int) Period #
Specify a factor for regular offset properties.
- Parameters:
n (int) – The factor.
- property seconds: Period#
Seconds regular offset property. Must be used only after
every
multiplier.
- property minutes: Period#
Minutes regular offset property. Must be used only after
every
multiplier.
- property hourly: Period#
Regular offset = every hour. The same as
.every(1).hours
. Can’t be combined with another regular offset.
- property daily: Period#
Regular offset = every day. The same as
.every(1).days
. Can’t be combined with another regular offset.
- property on: Period#
This property does nothing. It’s designed only to write better human-readable code, e.g.
.on.monday
.
- at(time: str) Period #
Specify the moment exact time (time offset, \(\Delta t_{time}\)).
- Parameters:
time (str) – Exact time. Format: “HH:MM” or “HH:MM:SS”.
- by(timezone: Union[tzinfo, str, int, float]) Period #
Specify the time zone for the exact time.
- Parameters:
timezone (Union[tzinfo, str, int, float]) – Time zone. If
str
, then it will be converted intotzinfo
viazoneinfo.ZoneInfo
. Ifint
orfloat
, then it will be used directly as an offset for the time offset.
- get_next(dt: datetime) datetime #
Get the next moment since passed moment.
- Parameters:
dt (datetime) – Current moment (\(t\))
- Returns:
The next moment (\(t + f(t)\))
- Return type:
datetime
- get_interval(dt: datetime) timedelta #
Get time to the next moment as timedelta since passed moment.
- Parameters:
dt (datetime) – Current moment (\(t\))
- Returns:
Interval to the next moment (\(f(t)\))
- Return type:
timedelta
- property is_timezone_in_use: bool#
If timezone is specified, return True, else False.
- property AND: Period#
This property does nothing. It’s designed only to write better human-readable code, e.g.
.on.monday.AND.tuesday
. It’s uppercase becauseand
is a reserved word in python.
- property OR: PeriodAggregation#
Create
PeriodAggregation
from this period and a new empty period.It’s designed to write better human-readable code, e.g.
.on.weekdays.at("18:00").OR.on.weekends.at("21:00")
. It’s uppercase becauseor
is a reserved word in python.
- __add__(other: Period) Period #
Combine periods as a sum of regular offset and time windows. Can’t sum objects with a different time offset and time zone.
- __or__(other: Union[Period, PeriodAggregation]) PeriodAggregation #
Create new
PeriodAggregation
from this period and the passed period.
PeriodAggregation#
- class regta_period.PeriodAggregation(*periods: Period)#
Bases:
AbstractPeriod
Aggregation class for
Period
.It contains the logic of how to get the nearest time moment and add data into the last period object.
- Parameters:
*periods (Tuple[Period]) – Periods to aggregate.
- get_next(dt: datetime) datetime #
Get the next moment since passed moment.
- Parameters:
dt (datetime) – Current moment (\(t\))
- Returns:
The next moment (\(t + f(t)\))
- Return type:
datetime
- get_interval(dt: datetime) timedelta #
Get time to the next moment as timedelta since passed moment.
- Parameters:
dt (datetime) – Current moment (\(t\))
- Returns:
Interval to the next moment (\(f(t)\))
- Return type:
timedelta
- property is_timezone_in_use: bool#
If timezone is specified, return True, else False.
- property OR: PeriodAggregation#
Create a new
PeriodAggregation
from these periods of aggregation and a new empty period.It’s designed to write better human-readable code, e.g.
.on.weekdays.at("18:00").OR.on.weekends.at("21:00")
. It’s uppercase becauseor
is a reserved word in python.
- __or__(other: Union[Period, PeriodAggregation]) PeriodAggregation #
Create a new
PeriodAggregation
from these periods of aggregation and the passed period.
- __dir__() Iterable[str] #
Extended implementation of the standard. It adds attributes of
Period
class.
- __getattr__(attr)#
Return an attribute of the last period in the list of periods with a wrap to return this object instead of the last period.