yggdrasil.data.cast.datetime¶
datetime ¶
truncate_datetime ¶
truncate_datetime(
value: Any,
interval: str | timedelta,
tz: str | tzinfo | timedelta | None = None,
add_interval: bool = False,
) -> dt.datetime
Truncate a datetime-like value to the boundary defined by interval.
Supported interval examples
- dt.timedelta(seconds=15)
- dt.timedelta(minutes=5)
- dt.timedelta(hours=4)
- dt.timedelta(days=7)
- "PT15S", "PT15M", "PT4H"
- "P1D", "P1W", "P1M", "P3M", "P1Y"
Rules
- timedelta and fixed-width ISO intervals truncate from Unix epoch.
- Calendar intervals (months/years) truncate from calendar boundaries.
- If add_interval=True and value is not already aligned, return the next boundary.
iter_datetime_ranges ¶
iter_datetime_ranges(
start: Any,
end: Any,
interval: str | timedelta,
tz: str | tzinfo | timedelta | None = None,
) -> Iterator[tuple[dt.datetime, dt.datetime]]
Iterate over aligned datetime ranges between start and end.
Supported interval examples
- dt.timedelta(seconds=30)
- dt.timedelta(minutes=15)
- dt.timedelta(hours=4)
- dt.timedelta(days=1)
- "PT1S", "PT30S"
- "PT1M", "PT15M"
- "PT1H", "PT4H"
- "P1D", "P7D"
- "P1W"
- "P1M", "P3M"
- "P1Y"