forked from microsoft/durabletask-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_internal.py
More file actions
38 lines (28 loc) · 1.17 KB
/
Copy path_internal.py
File metadata and controls
38 lines (28 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
"""Package-internal helpers shared across the history-export modules.
Names here have no leading underscore so they can be imported by sibling
modules without tripping pyright's ``reportPrivateUsage`` check. They
remain package-private by convention: nothing in this module is exported
from :mod:`durabletask.extensions.history_export.__init__`.
"""
from __future__ import annotations
from datetime import datetime, timezone
def dt_to_iso(value: datetime | None) -> str | None:
"""Normalize *value* to a UTC ISO-8601 string (or ``None``)."""
if value is None:
return None
if value.tzinfo is None:
value = value.replace(tzinfo=timezone.utc)
else:
value = value.astimezone(timezone.utc)
return value.isoformat()
def dt_from_iso(value: str | None) -> datetime | None:
"""Parse *value* as an ISO-8601 timestamp, defaulting naive values to UTC."""
if value is None:
return None
parsed = datetime.fromisoformat(value)
if parsed.tzinfo is None:
parsed = parsed.replace(tzinfo=timezone.utc)
return parsed
__all__ = ["dt_from_iso", "dt_to_iso"]