zcollection.merging.period.Period#

class zcollection.merging.period.Period(begin, end, *, within=False)[source]#

Bases: object

Create a Period from begin to last eg: [begin, last[

Parameters:
  • begin (numpy.datetime64) – The beginning of the period.

  • end (numpy.datetime64) – The ending of the period.

  • within (bool) – If true, the given period defines a closed interval (i.e. the end date is within the period), otherwise the interval is open.

Attributes

begin

Return the first element in the period.

last

Return the last item in the period.

Public Methods

contains(other)

Check if the given period is contains this period.

end()

Return one past the last element.

expand(duration)

Expand the size of the period by the duration on both ends.

from_duration(begin, duration)

Create a Period as [begin, begin + duration[

get_relation(other)

Get the relationship between the two time periods.

intersection(other)

Return the period of intersection or null period if no intersection.

intersects(other)

True if the periods overlap in any way.

is_adjacent(other)

True if periods are next to each other without a gap.

is_after(point)

True if all of the period is prior or point < start.

is_before(point)

True if all of the period is prior to the passed point or end <= point.

is_null()

True if period is ill formed (length is zero or less)

length()

Return the length of the period.

merge(other)

Return the union of intersecting periods -- or null period.

shift(duration)

Shift the start and end by the specified amount.

span(other)

Combine two periods with earliest start and latest end.

Protected Methods

_begin

The beginning of the period.

_duration_unit

The duration unit of the period.

_get_direct_relation(other)

Get the direct relation between two periods.

_last

The last date of the period.

Special Methods

__eq__(rhs)

Return self==value.

__getstate__()

Helper for pickle.

__lt__(rhs)

Return self<value.

__ne__(rhs)

Return self!=value.

__repr__()

Return repr(self).

__setstate__(state)