src.dackar.RCA.signal_evidence._util

Shared helpers for the signal-evidence package.

Centralizes the small utilities that were previously duplicated between builder.py and historian_adapter.py (MR#49 review), so the UTC-normalization rule below lives in exactly one place.

Functions

parse_dt(value)

Parse an ISO-8601 timestamp, normalized to a UTC-aware datetime.

clamp01(x)

Clamp x to the closed unit interval [0.0, 1.0].

Module Contents

src.dackar.RCA.signal_evidence._util.parse_dt(value)[source]

Parse an ISO-8601 timestamp, normalized to a UTC-aware datetime.

A naive input (no offset, e.g. "2024-01-01T00:00:00") is assumed to be UTC and stamped with timezone.utc, while offset-aware inputs (...+00:00 / ...Z) are preserved. This guarantees every downstream comparison and subtraction operates on offset-aware datetimes, avoiding TypeError: can't compare offset-naive and offset-aware datetimes.

Parameters:

value (Optional[str]) – An ISO-8601 timestamp string, or None/empty.

Returns:

A UTC-aware datetime, or None when value is empty or cannot be parsed.

Return type:

Optional[datetime.datetime]

src.dackar.RCA.signal_evidence._util.clamp01(x)[source]

Clamp x to the closed unit interval [0.0, 1.0].

Parameters:

x (float)

Return type:

float