[utils] unified_timestamp: Add tz_offset parameter (#15357)
Release (nightly) / check_nightly (push) Has been cancelled
Release (nightly) / release (push) Has been cancelled
Release (nightly) / publish_pypi (push) Has been cancelled
CodeQL / Analyze (actions) (push) Has been cancelled
CodeQL / Analyze (javascript-typescript) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Core Tests / Core Tests (ubuntu-latest, 3.11) (push) Has been cancelled
Core Tests / Core Tests (ubuntu-latest, 3.12) (push) Has been cancelled
Core Tests / Core Tests (ubuntu-latest, 3.13) (push) Has been cancelled
Core Tests / Core Tests (ubuntu-latest, 3.14) (push) Has been cancelled
Core Tests / Core Tests (ubuntu-latest, pypy-3.11) (push) Has been cancelled
Core Tests / Core Tests (windows-latest, 3.10) (push) Has been cancelled
Core Tests / Core Tests (windows-latest, 3.11) (push) Has been cancelled
Core Tests / Core Tests (windows-latest, 3.12) (push) Has been cancelled
Core Tests / Core Tests (windows-latest, 3.13) (push) Has been cancelled
Core Tests / Core Tests (windows-latest, 3.14) (push) Has been cancelled
Core Tests / Core Tests (windows-latest, pypy-3.11) (push) Has been cancelled
Download Tests / Quick Download Tests (push) Has been cancelled
Download Tests / Full Download Tests (ubuntu-latest, 3.11) (push) Has been cancelled
Download Tests / Full Download Tests (ubuntu-latest, 3.12) (push) Has been cancelled
Download Tests / Full Download Tests (ubuntu-latest, 3.13) (push) Has been cancelled
Download Tests / Full Download Tests (ubuntu-latest, 3.14) (push) Has been cancelled
Download Tests / Full Download Tests (ubuntu-latest, pypy-3.11) (push) Has been cancelled
Download Tests / Full Download Tests (windows-latest, 3.10) (push) Has been cancelled
Download Tests / Full Download Tests (windows-latest, pypy-3.11) (push) Has been cancelled
Quick Test / Core Test (push) Has been cancelled
Quick Test / Code check (push) Has been cancelled
Release (master) / release (push) Has been cancelled
Release (master) / publish_pypi (push) Has been cancelled
Keep cache warm / build (push) Has been cancelled

Allows datetime strings without a timezone to be parsed with the correct offset

Authored by: doe1080
This commit is contained in:
doe1080
2025-12-20 19:52:53 +00:00
committed by GitHub
parent 0ea6cc6d82
commit 15263d049c
2 changed files with 8 additions and 2 deletions
+4 -2
View File
@@ -1262,7 +1262,8 @@ def unified_strdate(date_str, day_first=True):
return str(upload_date)
def unified_timestamp(date_str, day_first=True):
@partial_application
def unified_timestamp(date_str, day_first=True, tz_offset=0):
if not isinstance(date_str, str):
return None
@@ -1270,7 +1271,8 @@ def unified_timestamp(date_str, day_first=True):
r'(?i)[,|]|(mon|tues?|wed(nes)?|thu(rs)?|fri|sat(ur)?|sun)(day)?', '', date_str))
pm_delta = 12 if re.search(r'(?i)PM', date_str) else 0
timezone, date_str = extract_timezone(date_str)
timezone, date_str = extract_timezone(
date_str, default=dt.timedelta(hours=tz_offset) if tz_offset else None)
# Remove AM/PM + timezone
date_str = re.sub(r'(?i)\s*(?:AM|PM)(?:\s+[A-Z]+)?', '', date_str)