Period.is_aligned#

Period.is_aligned(datetime_obj)[source]#

Return True if the supplied datetime is exactly the start of one of this period’s intervals.

Use it to check that a timestamp really falls on a period boundary before treating it as an interval start - e.g. that a value claiming to be hourly is on the hour, or that a reading sits on the 09:00 boundary of a hydrological day.

Parameters:

datetime_obj (datetime) – The datetime to test

Return type:

bool

Returns:

True if the datetime lies at the start of an interval, False otherwise

Examples

>>> from datetime import datetime
>>> pt1h = Period.of_hours(1)
>>> pt1h.is_aligned(datetime(2024, 3, 1, 9, 0))
True
>>> pt1h.is_aligned(datetime(2024, 3, 1, 9, 47))
False

An offset moves every boundary, and with it what counts as aligned.

>>> water_day = Period.of_days(1).with_hour_offset(9)
>>> water_day.is_aligned(datetime(2024, 3, 1, 9, 0))
True
>>> water_day.is_aligned(datetime(2024, 3, 1, 0, 0))
False