epicsarchiver.common.date_util
Utility functions for date formatting and validation.
Attributes
Exceptions
Exception raised for invalid date formats. |
Classes
A microsecond-precision UTC timestamp for archiver queries. |
|
A nanosecond-precision UTC timestamp from archiver responses. |
Functions
|
Add UTC timezone if timezone missing, otherwise convert to UTC. |
|
Seconds from Unix epoch at the start of a given year. |
|
Parse a date string using known formats. |
Module Contents
- epicsarchiver.common.date_util._DATE_FORMATS = ['%Y%m%d', '%Y%m%d %H:%M', '%Y%m%d %H:%M:%S', '%Y-%m-%d', '%Y-%m-%dT%H:%M', '%Y-%m-%d %H:%M',...[source]
- exception epicsarchiver.common.date_util.DateFormatError(date_str: str)[source]
Bases:
epicsarchiver.common.validation.ValidationErrorException raised for invalid date formats.
- epicsarchiver.common.date_util.ensure_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:
- epicsarchiver.common.date_util.year_start_epoch_seconds(year: int) int[source]
Seconds from Unix epoch at the start of a given year.
- epicsarchiver.common.date_util._parse_datetime_str(date_str: str) datetime.datetime[source]
Parse a date string using known formats.
- Parameters:
date_str – A date/datetime string.
- Returns:
UTC-aware datetime.
- Return type:
- Raises:
DateFormatError – If the string cannot be parsed.
- class epicsarchiver.common.date_util.QueryTimestamp(dt: datetime.datetime)[source]
A microsecond-precision UTC timestamp for archiver queries.
Wraps a UTC-aware datetime. Used for the input flow: user string/datetime to archiver HTTP query parameter.
- classmethod from_input(date_or_str: datetime.datetime | str) QueryTimestamp[source]
Parse user input (string or datetime).
Strings are parsed using a set of known formats. Strings without timezone information are treated as UTC. Datetimes are normalised to UTC.
- Parameters:
date_or_str – A datetime object or a date/datetime string.
- Returns:
QueryTimestamp
- classmethod from_datetime(dt: datetime.datetime) QueryTimestamp[source]
From a datetime (naive assumed UTC, aware converted).
- Parameters:
dt – A datetime object.
- Returns:
QueryTimestamp
- property datetime: datetime.datetime[source]
UTC-aware datetime.
- Returns:
UTC datetime
- Return type:
- class epicsarchiver.common.date_util.ResponseTimestamp(timestamp_ns: int)[source]
A nanosecond-precision UTC timestamp from archiver responses.
Internal representation is nanoseconds since Unix epoch (int). Used for the response flow: archiver data to datetime or display string. Precision is only lost when outputting to datetime (microsecond resolution).
- classmethod from_yearsecondnanos(year: int, seconds: int, nanos: int) ResponseTimestamp[source]
From archiver PB format.
Full nanosecond precision is preserved.
- property ns: int[source]
Nanoseconds since Unix epoch. Full precision.
- Returns:
nanoseconds since epoch
- Return type:
- property datetime: datetime.datetime[source]
UTC-aware datetime (microsecond precision).
Sub-microsecond nanoseconds are truncated.
- Returns:
UTC datetime
- Return type: