akkudoktoreos.utils.datetimeutil

Utility functions for date-time conversion tasks.

Functions:

  • to_datetime: Converts various date or time inputs to a timezone-aware or naive datetime object or formatted string.

  • to_duration: Converts various time delta inputs to a `timedelta`object.

  • to_timezone: Converts utc offset or location latitude and longitude to a timezone object.

Example usage:

# Date-time conversion >>> date_str = “2024-10-15” >>> date_obj = to_datetime(date_str) >>> print(date_obj) # Output: datetime object for ‘2024-10-15’

# Time delta conversion >>> to_duration(“2 days 5 hours”)

# Timezone detection >>> to_timezone(location=(40.7128, -74.0060))

Functions

compare_datetimes(dt1, dt2[, tolerance])

Compares two Pendulum DateTime objects with precision, including DST and timezones.

hours_in_day([dt])

Returns the number of hours in the given date's day, considering DST transitions.

to_datetime()

Convert a date input into a Pendulum DateTime object or a formatted string, with optional timezone handling.

to_duration(input_value)

Converts various input types into a Duration object using pendulum.

to_timezone()

Determines the timezone either by UTC offset, geographic location, or local system timezone.

Classes

DatetimesComparisonResult(equal, ...)

Encapsulates the result of comparing two Pendulum DateTime objects.