Convert timestamps to UTC in reformat_date
- ID
6063cf9- date
2025-12-01 21:52:36+00:00- author
Alex Chan <alex@alexwlchan.net>- parent
689a15f- message
Convert timestamps to UTC in `reformat_date`- changed files
4 files, 8 additions, 1 deletion
Changed files
CHANGELOG.md (521) → CHANGELOG.md (613)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d9ec7f3..0ea483a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,9 @@
# CHANGELOG
+## v5 - 2025-12-01
+
+When calling `reformat_date()`, ensure all dates are converted to UTC.
+
## v4 - 2025-11-29
Rename `chives.timestamps` to `chives.dates`.
src/chives/__init__.py (390) → src/chives/__init__.py (390)
diff --git a/src/chives/__init__.py b/src/chives/__init__.py
index 6c780be..74de00f 100644
--- a/src/chives/__init__.py
+++ b/src/chives/__init__.py
@@ -11,4 +11,4 @@ I share across multiple sites.
"""
-__version__ = "4"
+__version__ = "5"
src/chives/dates.py (2122) → src/chives/dates.py (2174)
diff --git a/src/chives/dates.py b/src/chives/dates.py
index 272d651..1fe4258 100644
--- a/src/chives/dates.py
+++ b/src/chives/dates.py
@@ -70,4 +70,6 @@ def reformat_date(s: str, /, orig_fmt: str) -> str:
d = d.replace(microsecond=0)
if d.tzinfo is None:
d = d.replace(tzinfo=timezone.utc)
+ else:
+ d = d.astimezone(tz=timezone.utc)
return d.strftime("%Y-%m-%dT%H:%M:%S%z").replace("+0000", "Z")
tests/test_dates.py (2021) → tests/test_dates.py (2107)
diff --git a/tests/test_dates.py b/tests/test_dates.py
index 74c9128..107cff2 100644
--- a/tests/test_dates.py
+++ b/tests/test_dates.py
@@ -55,6 +55,7 @@ def test_date_matches_any_format() -> None:
("2025-11-12T15:34:39.570Z", "%Y-%m-%dT%H:%M:%S.%fZ", "2025-11-12T15:34:39Z"),
("2025-03-12 09:57:03", "%Y-%m-%d %H:%M:%S", "2025-03-12T09:57:03Z"),
("2016-02-25 05:28:35 GMT", "%Y-%m-%d %H:%M:%S %Z", "2016-02-25T05:28:35Z"),
+ ("2011-12-06T10:45:15-08:00", "%Y-%m-%dT%H:%M:%S%z", "2011-12-06T18:45:15Z"),
],
)
def test_reformat_date(s: str, orig_fmt: str, formatted_date: str) -> None: