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 into tzinfo via zoneinfo.ZoneInfo. If int or float, 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 hours: Period#

Hours regular offset property. Must be used only after every multiplier.

property days: Period#

Days 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.

property monday: Period#

Add Monday to the time windows list.

property tuesday: Period#

Add Tuesday to the time windows list.

property wednesday: Period#

Add Wednesday to the time windows list.

property thursday: Period#

Add Thursday to the time windows list.

property friday: Period#

Add Friday to the time windows list.

property saturday: Period#

Add Saturday to the time windows list.

property sunday: Period#

Add Sunday to the time windows list.

property weekdays: Period#

Add weekdays (Monday-Friday) to the time windows list.

property weekends: Period#

Add weekends (Saturday-Sunday) to the time windows list.

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 into tzinfo via zoneinfo.ZoneInfo. If int or float, 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 because and 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 because or 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.

periods#

Aggregated periods.

Type:

Tuple[Period]

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 because or 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.

Weekdays#

class regta_period.Weekdays(value)#

Bases: Enum

An enumeration of weekdays for the time windows logic.

MONDAY = 0#
TUESDAY = 1#
WEDNESDAY = 2#
THURSDAY = 3#
FRIDAY = 4#
SATURDAY = 5#
SUNDAY = 6#
classmethod get(dt: datetime) Weekdays#

Create a Weekdays object by a datetime object.