"""Time and timestamp utilities for internal use"""from__future__importannotationsimportdatetimeimportemail.utils
[docs]classTime:"""Time and timestamp utilities"""
[docs]@staticmethoddeftimestamp_to_dt(timestamp:int|float)->datetime.datetime:"""Convert POSIX timestamp to datetime in UTC timezone. :param timestamp: UTC-based POSIX timestamp :return: :class:`datetime.datetime` in UTC timezone """returndatetime.datetime.fromtimestamp(timestamp,datetime.timezone.utc)
[docs]@staticmethoddeftimestamp_to_http_date(timestamp:int|float)->str:"""Convert POSIX timestamp to HTTP date in GMT timezone. :param timestamp: POSIX timestamp :return: RFC-822 date suitable for HTTP headers """returnemail.utils.formatdate(round(timestamp),usegmt=True)
[docs]@staticmethoddeftimestamp_delta(timestamp_delta:int|float)->datetime.timedelta:"""Convert POSIX timestamp difference to a printable datetime duration. :param timestamp_delta: time period in seconds :return: :class:`datetime.datetime` duration, rounded to non-fractional seconds """returndatetime.timedelta(seconds=round(timestamp_delta))