animedex.utils.timezone
Timezone parsing helpers shared by aggregate commands and renderers.
The CLI accepts fixed offsets, IANA names, local time, and the broader
set of timezone strings supported by dateutil.tz. Keeping this
logic in one module avoids each command growing a slightly different
timezone parser.
TimezoneResolution
- class animedex.utils.timezone.TimezoneResolution(tzinfo: tzinfo, label: str)[source]
Bases:
objectResolved timezone value and display label.
- Variables:
tzinfo (datetime.tzinfo) – Concrete timezone object used for datetime math.
label (str) – Stable human-readable label carried into rendered aggregate results.
now_local
timezone_label
- animedex.utils.timezone.timezone_label(tz: tzinfo, *, sample: datetime | None = None) str[source]
Return a stable display label for a timezone object.
- Parameters:
tz (datetime.tzinfo) – Timezone object.
sample (datetime.datetime or None) – Optional datetime used for offset/name sampling.
- Returns:
IANA key,
"UTC", fixed offset, or timezone name.- Return type:
parse_timezone
- animedex.utils.timezone.parse_timezone(value: str | None, *, local_now: datetime | None = None) TimezoneResolution[source]
Parse a user-facing timezone string.
Accepted forms include
local,UTC/Z/GMT, IANA names such asAsia/Tokyo, fixed offsets such as+08:00or+8, prefixed offsets such asUTC+8orGMT-05:00, and any additional timezone syntax understood bydateutil.tz.gettz().- Parameters:
value (str or None) – User-provided timezone value.
Nonemeans local.local_now (datetime.datetime or None) – Optional local datetime override for tests.
- Returns:
Resolved timezone and display label.
- Return type:
- Raises:
ValueError – If the value cannot be parsed.