Use a named local timezone for better display of historical dates in the local timezone

See #2133435 (Suggestion for timezone handling (linux example included))
This commit is contained in:
Kovid Goyal 2025-11-30 20:23:08 +05:30
parent e1e4aa46aa
commit 59cee5b4df
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 10 additions and 1 deletions

View File

@ -54,6 +54,8 @@ dependencies = [
"PyQt6_WebEngine == 6.8.0",
"MacFSEvents == 0.8.4; sys_platform == 'darwin'",
"xxhash == 3.3.0",
"tzdata == 2025.2",
"tzlocal == 5.3.1",
]
[project.urls]

View File

@ -3,11 +3,18 @@
from datetime import datetime, timedelta, timezone
from zoneinfo import ZoneInfo
import tzlocal
from calibre_extensions import speedup
utc_tz = timezone.utc
local_tz = datetime.now().astimezone().tzinfo
try:
tz_name = tzlocal.get_localzone_name()
local_tz = ZoneInfo(tz_name)
except Exception:
local_tz = datetime.now().astimezone().tzinfo
UNDEFINED_DATE = datetime(101,1,1, tzinfo=utc_tz)