mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Simplify import process for zoneinfo backport across entire project
This commit is contained in:
parent
d35d718a62
commit
3602afadbb
2 changed files with 4 additions and 10 deletions
|
|
@ -10,7 +10,7 @@ from jinja2 import Environment, FileSystemLoader
|
|||
try:
|
||||
import zoneinfo
|
||||
except ModuleNotFoundError:
|
||||
import backports.zoneinfo
|
||||
from backports import zoneinfo
|
||||
|
||||
try:
|
||||
import readline # NOQA
|
||||
|
|
@ -161,10 +161,7 @@ def ask(question, answer=str, default=None, length=None):
|
|||
|
||||
def ask_timezone(question, default, tzurl):
|
||||
"""Prompt for time zone and validate input"""
|
||||
try:
|
||||
tz_dict = {tz.lower(): tz for tz in zoneinfo.available_timezones()}
|
||||
except NameError:
|
||||
tz_dict = {tz.lower(): tz for tz in backports.zoneinfo.available_timezones()}
|
||||
tz_dict = {tz.lower(): tz for tz in zoneinfo.available_timezones()}
|
||||
while True:
|
||||
r = ask(question, str, default)
|
||||
r = r.strip().replace(" ", "_").lower()
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ import dateutil.parser
|
|||
try:
|
||||
import zoneinfo
|
||||
except ModuleNotFoundError:
|
||||
import backports.zoneinfo
|
||||
from backports import zoneinfo
|
||||
from markupsafe import Markup
|
||||
|
||||
|
||||
|
|
@ -921,10 +921,7 @@ 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:
|
||||
try:
|
||||
timezone = zoneinfo.ZoneInfo(tz_name)
|
||||
except NameError:
|
||||
timezone = backports.zoneinfo.ZoneInfo(tz_name)
|
||||
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue