From c94f0e7d35792926a106a275668b6ab7d42d1223 Mon Sep 17 00:00:00 2001 From: Jacob Repp Date: Wed, 4 Feb 2026 11:04:25 -0600 Subject: [PATCH] fix: use UTC timezone instead of local for timestamp conversion The previous code used `astimezone(tz=None)` which converts to local timezone, but then formatted with 'Z' suffix which implies UTC. This caused timestamps to be offset by the local timezone. Example with CST (UTC-6): - Git timestamp: 2025-10-16T23:09:56-07:00 - Bug output: 2025-10-17T01:09:56Z (local time with Z suffix) - Fixed output: 2025-10-17T06:09:56Z (actual UTC) Changed `astimezone(tz=None)` to `astimezone(timezone.utc)` for both created and updated timestamp conversions. --- docuchango/fixes/timestamps.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docuchango/fixes/timestamps.py b/docuchango/fixes/timestamps.py index af4ae66..9215e8c 100644 --- a/docuchango/fixes/timestamps.py +++ b/docuchango/fixes/timestamps.py @@ -11,7 +11,7 @@ import re import subprocess -from datetime import datetime +from datetime import datetime, timezone from pathlib import Path import frontmatter @@ -48,7 +48,7 @@ def get_git_dates(file_path: Path) -> tuple[str | None, str | None]: # Replace 'Z' with '+00:00' for Python 3.9/3.10 compatibility (Python 3.11+ handles 'Z' natively) first_commit = first_commit.replace("Z", "+00:00") # Convert to UTC and format as ISO 8601 datetime - created_dt = datetime.fromisoformat(first_commit).astimezone(tz=None) + created_dt = datetime.fromisoformat(first_commit).astimezone(timezone.utc) created_datetime = created_dt.strftime("%Y-%m-%dT%H:%M:%SZ") # Get last commit date (update) @@ -66,7 +66,7 @@ def get_git_dates(file_path: Path) -> tuple[str | None, str | None]: # Replace 'Z' with '+00:00' for Python 3.9/3.10 compatibility (Python 3.11+ handles 'Z' natively) last_commit = last_commit.replace("Z", "+00:00") # Convert to UTC and format as ISO 8601 datetime - updated_dt = datetime.fromisoformat(last_commit).astimezone(tz=None) + updated_dt = datetime.fromisoformat(last_commit).astimezone(timezone.utc) updated_datetime = updated_dt.strftime("%Y-%m-%dT%H:%M:%SZ") return created_datetime, updated_datetime