Skip to content

Commit

Permalink
Fixes getpelican#2958. Replaces pytz dependency with zoneinfo.
Browse files Browse the repository at this point in the history
  • Loading branch information
willthong committed Jul 24, 2023
1 parent b8bf595 commit 66b2076
Show file tree
Hide file tree
Showing 5 changed files with 456 additions and 364 deletions.
3 changes: 3 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Release type: minor

Replace `pytz` with native alternatives.
19 changes: 14 additions & 5 deletions pelican/contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@
from html import unescape
from urllib.parse import unquote, urljoin, urlparse, urlunparse

import pytz
from datetime import timezone

try:
import zoneinfo
except ModuleNotFoundError:
import backports.zoneinfo


from pelican.plugins import signals
from pelican.settings import DEFAULT_CONFIG
Expand Down Expand Up @@ -120,9 +126,12 @@ def __init__(self, content, metadata=None, settings=None,
self.date_format = self.date_format[1]

# manage timezone
default_timezone = settings.get('TIMEZONE', 'UTC')
timezone = getattr(self, 'timezone', default_timezone)
self.timezone = pytz.timezone(timezone)
default_timezone = settings.get("TIMEZONE", "UTC")
timezone = getattr(self, "timezone", default_timezone)
try:
self.timezone = zoneinfo.ZoneInfo(timezone)
except NameError:
self.timezone = backports.zoneinfo.ZoneInfo(timezone)

if hasattr(self, 'date'):
self.date = set_date_tzinfo(self.date, timezone)
Expand Down Expand Up @@ -525,7 +534,7 @@ def __init__(self, *args, **kwargs):
if self.date.tzinfo is None:
now = datetime.datetime.now()
else:
now = datetime.datetime.utcnow().replace(tzinfo=pytz.utc)
now = datetime.datetime.utcnow().replace(tzinfo=timezone.utc)
if self.date > now:
self.status = 'draft'

Expand Down
Loading

0 comments on commit 66b2076

Please sign in to comment.