1
0
Fork 0
forked from github/pelican

Replace pytz dependency with zoneinfo. Fix #2958 (#3161)

This commit is contained in:
Will Thong 2023-07-26 16:29:43 +01:00 committed by GitHub
commit 1d2bf8e96e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 33 additions and 23 deletions

View file

@ -18,10 +18,12 @@ from operator import attrgetter
import dateutil.parser
try:
import zoneinfo
except ModuleNotFoundError:
from backports import zoneinfo
from markupsafe import Markup
import pytz
logger = logging.getLogger(__name__)
@ -919,10 +921,11 @@ class FileSystemWatcher:
def set_date_tzinfo(d, tz_name=None):
"""Set the timezone for dates that don't have tzinfo"""
if tz_name and not d.tzinfo:
tz = pytz.timezone(tz_name)
d = tz.localize(d)
return SafeDatetime(d.year, d.month, d.day, d.hour, d.minute, d.second,
d.microsecond, d.tzinfo)
timezone = zoneinfo.ZoneInfo(tz_name)
d = d.replace(tzinfo=timezone)
return SafeDatetime(
d.year, d.month, d.day, d.hour, d.minute, d.second, d.microsecond, d.tzinfo
)
return d