mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
utils: Use pytz instead of datetime.timezone for timezones
datetime.timezone is new in Python 3.2 [1], so pytz allows us to keep support for Python 2.7. [1]: http://docs.python.org/dev/library/datetime.html#datetime.timezone
This commit is contained in:
parent
228fc82fc9
commit
1102143c33
2 changed files with 9 additions and 7 deletions
|
|
@ -9,6 +9,8 @@ import locale
|
|||
from sys import platform, version_info
|
||||
from tempfile import mkdtemp
|
||||
|
||||
import pytz
|
||||
|
||||
from pelican.generators import TemplatePagesGenerator
|
||||
from pelican.writers import Writer
|
||||
from pelican.settings import read_settings
|
||||
|
|
@ -43,13 +45,13 @@ class TestUtils(LoggedTestCase):
|
|||
year=2012, month=11, day=22, hour=22, minute=11, second=10)
|
||||
date_hour_sec_z = datetime.datetime(
|
||||
year=2012, month=11, day=22, hour=22, minute=11, second=10,
|
||||
tzinfo=datetime.timezone.utc)
|
||||
date_hour_sec_0430 = datetime.datetime(
|
||||
tzinfo=pytz.timezone('UTC'))
|
||||
date_hour_sec_est = datetime.datetime(
|
||||
year=2012, month=11, day=22, hour=22, minute=11, second=10,
|
||||
tzinfo=datetime.timezone(datetime.timedelta(hours=4, minutes=30)))
|
||||
tzinfo=pytz.timezone('EST'))
|
||||
date_hour_sec_frac_z = datetime.datetime(
|
||||
year=2012, month=11, day=22, hour=22, minute=11, second=10,
|
||||
microsecond=123000, tzinfo=datetime.timezone.utc)
|
||||
microsecond=123000, tzinfo=pytz.timezone('UTC'))
|
||||
dates = {
|
||||
'2012-11-22': date,
|
||||
'2012/11/22': date,
|
||||
|
|
@ -61,7 +63,7 @@ class TestUtils(LoggedTestCase):
|
|||
'22.11.2012 22:11': date_hour,
|
||||
'2012-11-22 22:11:10': date_hour_sec,
|
||||
'2012-11-22T22:11:10Z': date_hour_sec_z,
|
||||
'2012-11-22T22:11:10+0430': date_hour_sec_0430,
|
||||
'2012-11-22T22:11:10-0500': date_hour_sec_est,
|
||||
'2012-11-22T22:11:10.123Z': date_hour_sec_frac_z,
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ from collections import Hashable
|
|||
from functools import partial
|
||||
|
||||
from codecs import open, BOM_UTF8
|
||||
from datetime import datetime, timezone
|
||||
from datetime import datetime
|
||||
from itertools import groupby
|
||||
from jinja2 import Markup
|
||||
from operator import attrgetter
|
||||
|
|
@ -210,7 +210,7 @@ def get_date(string):
|
|||
except ValueError:
|
||||
continue
|
||||
if date_format.endswith('Z'):
|
||||
date = date.replace(tzinfo=timezone.utc)
|
||||
date = date.replace(tzinfo=pytz.timezone('UTC'))
|
||||
return date
|
||||
raise ValueError('{0!r} is not a valid date'.format(string))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue