pyacs.lib.timeperiod.time_period

Time period representation and manipulation.

class pyacs.lib.timeperiod.time_period.TimePeriod(start_time=None, end_time=None)[source]

Bases: object

A time period with start and end datetime.

__start_time

Start of the period.

Type:

datetime, optional

__end_time

End of the period.

Type:

datetime, optional

begin()

Return the start datetime of this period.

Returns:

Start time.

Return type:

datetime

Raises:

TimePeriodUndefinedError – If the period is not defined.

display()
end()

Return the end datetime of this period.

Returns:

End time.

Return type:

datetime

Raises:

TimePeriodUndefinedError – If the period is not defined.

epoch_begin()

Return the start time as Unix timestamp (epoch seconds).

Returns:

Start time in epoch seconds.

Return type:

int

Raises:

TimePeriodUndefinedError – If the period is not defined.

epoch_end()

Return the end time as Unix timestamp (epoch seconds).

Returns:

End time in epoch seconds.

Return type:

int

Raises:

TimePeriodUndefinedError – If the period is not defined.

get_info()
has_in(date)

Return whether a date falls within this period.

Parameters:

date (datetime) – Date to test.

Returns:

True if date is in [start, end], False otherwise.

Return type:

bool

intersection(period)

Return the intersection of this period with another.

Parameters:

period (TimePeriod) – The other time period.

Returns:

Intersection period, or undefined if no overlap.

Return type:

TimePeriod

isdefined()

Return True if both start and end times are set.