AvailableAt#
- class openstef_core.types.AvailableAt(day_offset: int, time_of_day: time, *, tzinfo: BaseTzInfo | timezone | None = None)[source]#
Bases:
PydanticStringPrimitiveRepresents a time point available relative to a reference day.
Uses a specialized string format
DnTHHMMwhere:n is the day offset (negative or zero)
HHMM is the time of day
An optional timezone suffix
[Region/City](RFC 9557 bracket notation) makes the availability time timezone-aware. Both pytz and stdlibdatetime.timezoneobjects are accepted; they round-trip through the IANA name viastr(tz)/pytz.timezone(name).For example,
D-1T0600[Europe/Amsterdam]means “6:00 Europe/Amsterdam on the previous day”. The legacyDnTHH:MMformat (with colon) is also accepted byfrom_string().Example
>>> from datetime import time >>> import pytz >>> tz_at = AvailableAt(day_offset=-1, time_of_day=time(6, 0), tzinfo=pytz.timezone('Europe/Amsterdam')) >>> str(tz_at) 'D-1T0600[Europe/Amsterdam]' >>> at = AvailableAt.from_string("D-1T0600") >>> at.day_offset, at.time_of_day (-1, datetime.time(6, 0))
- __init__(day_offset: int, time_of_day: time, *, tzinfo: BaseTzInfo | timezone | None = None)[source]#
Initialise with a day offset, time of day, and optional timezone.
- Parameters:
day_offset (
int) – Day offset from the reference day (must be ≤ 0).-1means “the previous day”,0means “the same day”.time_of_day (
time) – Clock time when data becomes available.tzinfo (
BaseTzInfo|timezone|None) – Optional timezone for the availability time (e.g.pytz.timezone("Europe/Amsterdam"),pytz.UTC, ordatetime.timezone.utc).day_offset
time_of_day
tzinfo
- Raises:
ValueError – If day_offset is positive.
- __str__() str[source]#
Converts to string in
DnTHHMMorDnTHHMM[tz]format.- Return type:
- Returns:
String representation, with optional
[timezone]suffix.
- classmethod from_string(s: str) Self[source]#
Creates an instance from a string in
DnTHHMM[tz]format.Accepts an optional
[Region/City]timezone suffix. The legacy colon formatDnTHH:MMis also accepted.- Parameters:
s (
str) – String to parse.s
- Returns:
AvailableAt instance parsed from the string.
- Raises:
ValueError – If the string format is invalid or day offset is positive.
- Return type:
Self
- apply(date: datetime) datetime[source]#
Apply this availability offset to a reference date.
The day offset is interpreted in
self.tzinfo(falls back todate.tzinfo), so “D-1” means “the previous calendar day in that timezone”. The time-of-day is also placed in that timezone. The result is returned in the reference date’s timezone, or naive when the reference date is naive.This matches the vectorised
apply_index()semantics, which converts toself.tzinfobefore extracting the calendar day.
- apply_index(index: DatetimeIndex) DatetimeIndex[source]#
Vectorized version of
apply()for a pandas DatetimeIndex.Same timezone logic as
apply(): the time-of-day is interpreted inself.tzinfo(falls back toindex.tz), then converted back to the index’s timezone.- Parameters:
index (
DatetimeIndex) – DatetimeIndex of reference dates.index
- Returns:
DatetimeIndex of cutoff timestamps, in the same timezone as index.
- Return type:
DatetimeIndex