lair.clock.dt2decimalDate#
- lair.clock.dt2decimalDate(datetime)[source]#
Convert a datetime object to a decimal date.
Naive datetimes are used as-is (by convention they are UTC). Timezone-aware datetimes (incl. tz-aware
pd.Timestamp) are converted to UTC first, so the decimal date counts elapsed time from Jan 1 00:00 UTC of the UTC year. This gives the same answer for pytz and zoneinfo zones, and keeps the two instants of a DST fall-back hour distinct and in order.- Parameters:
datetime (dt.datetime) – The datetime object to convert.
- Returns:
float – The decimal date.
- Return type:
See also
decimalDate2dtThe other way.
Examples
>>> import datetime as dt >>> from lair.clock import dt2decimalDate >>> round(dt2decimalDate(dt.datetime(2024, 7, 1)), 4) # 182 of 366 days 2024.4973