epicsarchiver.common.date_util

Utility functions for date formatting and validation.

Exceptions

DateFormatError

Exception raised for invalid date formats.

Functions

datetime_from_str(→ datetime.datetime)

Formats a date or string to a datetime object.

format_date(→ str)

Format a datetime object to a string in ISO 8601 format with UTC timezone.

set_timezone_utc(→ datetime.datetime)

Add UTC timezone if timezone missing, otherwise convert to UTC.

Module Contents

exception epicsarchiver.common.date_util.DateFormatError(date_str: str)[source]

Bases: epicsarchiver.common.validation.ValidationError

Exception raised for invalid date formats.

epicsarchiver.common.date_util.datetime_from_str(date_or_str: datetime.datetime | str) datetime.datetime[source]

Formats a date or string to a datetime object.

If the input is a string, it attempts to parse it into a datetime object. If the input is already a datetime object, it returns it without timezone info.

All timezone information is stripped from the datetime object.

Parameters:

date_or_str – can be a datetime object or string

Returns:

datetime object without timezone info.

Return type:

datetime.datetime

Raises:

DateFormatError – If the string cannot be parsed into a datetime object.

epicsarchiver.common.date_util.format_date(at: datetime.datetime) str[source]

Format a datetime object to a string in ISO 8601 format with UTC timezone.

Parameters:

at (datetime.datetime) – The datetime object to format.

Returns:

Formatted date string in ISO 8601 format with ‘Z’ suffix.

Return type:

str

epicsarchiver.common.date_util.set_timezone_utc(input_time: datetime.datetime) datetime.datetime[source]

Add UTC timezone if timezone missing, otherwise convert to UTC.

Parameters:

input_time (datetime.datetime) – A timestamp object.

Returns:

A timestamp object with timezone set to UTC.

Return type:

input_time (datetime.datetime)