Period.is_subperiod_of#

Period.is_subperiod_of(other)[source]#

Return True if every interval of this period falls entirely inside a single interval of other.

Each of this period’s intervals must lie wholly within one of other’s, never straddling a boundary - but different intervals of other may hold different numbers of them. A day is a subperiod of a month for exactly that reason: no day ever spans a month boundary, even though months hold 28 to 31 of them.

It follows that a larger period is never a subperiod of a smaller one, and that a period is always a subperiod of itself. The two must also agree on timezone: a period at UTC is not a subperiod of one at +05:00, nor of a naive one.

Parameters:

other (Period) – The period whose intervals must contain this period’s

Return type:

bool

Returns:

True if every interval of this period lies within one interval of other, False otherwise

Examples

>>> pt1h, p1d, p1m = Period.of_hours(1), Period.of_days(1), Period.of_months(1)

An hour never straddles a midnight boundary, nor a day a month boundary - even though months vary in length.

>>> pt1h.is_subperiod_of(p1d)
True
>>> p1d.is_subperiod_of(p1m)
True

The larger period is never contained by the smaller.

>>> p1d.is_subperiod_of(pt1h)
False

Offsetting one of them makes its intervals straddle the other’s boundaries …

>>> pt1h_t1m = Period.of_hours(1).with_minute_offset(1)
>>> pt1h_t1m.is_subperiod_of(p1d)
False

… unless both are offset alike.

>>> pt1h_t1m.is_subperiod_of(Period.of_days(1).with_minute_offset(1))
True