summaryrefslogtreecommitdiff
path: root/django/utils/dateparse.py
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2013-09-08 10:43:33 +0200
committerAymeric Augustin <aymeric.augustin@m4x.org>2013-09-09 22:32:52 +0200
commitd9413d33b2a8371731a92289123683cf6f440290 (patch)
tree2f90f5ad6e1e63d25a619f9985acb1a0bf9c61e5 /django/utils/dateparse.py
parentec2778b445546f624d3b3a1f2118e751b10bb2e7 (diff)
Refactored code and tests that relied on django.utils.tzinfo.
Refs #17262.
Diffstat (limited to 'django/utils/dateparse.py')
-rw-r--r--django/utils/dateparse.py9
1 files changed, 5 insertions, 4 deletions
diff --git a/django/utils/dateparse.py b/django/utils/dateparse.py
index b4bd559a66..1e2cad7d01 100644
--- a/django/utils/dateparse.py
+++ b/django/utils/dateparse.py
@@ -8,8 +8,8 @@
import datetime
import re
from django.utils import six
-from django.utils.timezone import utc
-from django.utils.tzinfo import FixedOffset
+from django.utils.timezone import utc, get_fixed_timezone
+
date_re = re.compile(
r'(?P<year>\d{4})-(?P<month>\d{1,2})-(?P<day>\d{1,2})$'
@@ -27,6 +27,7 @@ datetime_re = re.compile(
r'(?P<tzinfo>Z|[+-]\d{2}:?\d{2})?$'
)
+
def parse_date(value):
"""Parses a string and return a datetime.date.
@@ -59,7 +60,7 @@ def parse_datetime(value):
"""Parses a string and return a datetime.datetime.
This function supports time zone offsets. When the input contains one,
- the output uses an instance of FixedOffset as tzinfo.
+ the output uses a timezone with a fixed offset from UTC.
Raises ValueError if the input is well formatted but not a valid datetime.
Returns None if the input isn't well formatted.
@@ -76,7 +77,7 @@ def parse_datetime(value):
offset = 60 * int(tzinfo[1:3]) + int(tzinfo[-2:])
if tzinfo[0] == '-':
offset = -offset
- tzinfo = FixedOffset(offset)
+ tzinfo = get_fixed_timezone(offset)
kw = dict((k, int(v)) for k, v in six.iteritems(kw) if v is not None)
kw['tzinfo'] = tzinfo
return datetime.datetime(**kw)