Merge msiedlarek-master.
Add changelog entry.
This commit is contained in:
@@ -4,6 +4,8 @@ Unreleased
|
|||||||
Features
|
Features
|
||||||
~~~~~~~~
|
~~~~~~~~
|
||||||
|
|
||||||
|
- Support spec-mandated truncations of ISO-8601 timezones.
|
||||||
|
|
||||||
- Support spec-mandated truncations of ISO-8601 datetimes.
|
- Support spec-mandated truncations of ISO-8601 datetimes.
|
||||||
|
|
||||||
- Allow specifying custom representations of values for boolean fields.
|
- Allow specifying custom representations of values for boolean fields.
|
||||||
|
@@ -41,10 +41,10 @@ __all__ = ["parse_date", "ParseError", "Utc", "FixedOffset"]
|
|||||||
ISO8601_REGEX = re.compile(
|
ISO8601_REGEX = re.compile(
|
||||||
r"(?P<year>[0-9]{4})(-(?P<month>[0-9]{1,2})(-(?P<day>[0-9]{1,2})"
|
r"(?P<year>[0-9]{4})(-(?P<month>[0-9]{1,2})(-(?P<day>[0-9]{1,2})"
|
||||||
r"((?P<separator>.)(?P<hour>[0-9]{2})(:(?P<minute>[0-9]{2})(:(?P<second>[0-9]{2})(\.(?P<fraction>[0-9]+))?)?)?"
|
r"((?P<separator>.)(?P<hour>[0-9]{2})(:(?P<minute>[0-9]{2})(:(?P<second>[0-9]{2})(\.(?P<fraction>[0-9]+))?)?)?"
|
||||||
r"(?P<timezone>Z|(([-+])([0-9]{2}):([0-9]{2})))?)?)?)?"
|
r"(?P<timezone>Z|(([-+])([0-9]{2})(:?([0-9]{2}))?))?)?)?)?"
|
||||||
)
|
)
|
||||||
TIMEZONE_REGEX = re.compile(
|
TIMEZONE_REGEX = re.compile(
|
||||||
"(?P<prefix>[+-])(?P<hours>[0-9]{2}).(?P<minutes>[0-9]{2})")
|
"(?P<prefix>[+-])(?P<hours>[0-9]{2})(:?(?P<minutes>[0-9]{2}))?")
|
||||||
|
|
||||||
class ParseError(Exception):
|
class ParseError(Exception):
|
||||||
"""Raised when there is a problem parsing a date string"""
|
"""Raised when there is a problem parsing a date string"""
|
||||||
@@ -97,8 +97,13 @@ def parse_timezone(tzstring, default_timezone=UTC):
|
|||||||
if tzstring is None:
|
if tzstring is None:
|
||||||
return default_timezone
|
return default_timezone
|
||||||
m = TIMEZONE_REGEX.match(tzstring)
|
m = TIMEZONE_REGEX.match(tzstring)
|
||||||
prefix, hours, minutes = m.groups()
|
prefix = m.group('prefix')
|
||||||
hours, minutes = int(hours), int(minutes)
|
hours = int(m.group('hours'))
|
||||||
|
minutes = m.group('minutes')
|
||||||
|
if minutes is None:
|
||||||
|
minutes = 0
|
||||||
|
else:
|
||||||
|
minutes = int(minutes)
|
||||||
if prefix == "-":
|
if prefix == "-":
|
||||||
hours = -hours
|
hours = -hours
|
||||||
minutes = -minutes
|
minutes = -minutes
|
||||||
|
@@ -70,12 +70,36 @@ class Test_parse_timezone(unittest.TestCase):
|
|||||||
self.assertEqual(result.utcoffset(None),
|
self.assertEqual(result.utcoffset(None),
|
||||||
datetime.timedelta(hours=1, minutes=0))
|
datetime.timedelta(hours=1, minutes=0))
|
||||||
|
|
||||||
|
def test_positive_without_colon(self):
|
||||||
|
tzstring = "+0100"
|
||||||
|
result = self._callFUT(tzstring)
|
||||||
|
self.assertEqual(result.utcoffset(None),
|
||||||
|
datetime.timedelta(hours=1, minutes=0))
|
||||||
|
|
||||||
|
def test_positive_without_minutes(self):
|
||||||
|
tzstring = "+01"
|
||||||
|
result = self._callFUT(tzstring)
|
||||||
|
self.assertEqual(result.utcoffset(None),
|
||||||
|
datetime.timedelta(hours=1, minutes=0))
|
||||||
|
|
||||||
def test_negative(self):
|
def test_negative(self):
|
||||||
tzstring = "-01:00"
|
tzstring = "-01:00"
|
||||||
result = self._callFUT(tzstring)
|
result = self._callFUT(tzstring)
|
||||||
self.assertEqual(result.utcoffset(None),
|
self.assertEqual(result.utcoffset(None),
|
||||||
datetime.timedelta(hours=-1, minutes=0))
|
datetime.timedelta(hours=-1, minutes=0))
|
||||||
|
|
||||||
|
def test_negative_without_colon(self):
|
||||||
|
tzstring = "-0100"
|
||||||
|
result = self._callFUT(tzstring)
|
||||||
|
self.assertEqual(result.utcoffset(None),
|
||||||
|
datetime.timedelta(hours=-1, minutes=0))
|
||||||
|
|
||||||
|
def test_negative_without_minutes(self):
|
||||||
|
tzstring = "-01"
|
||||||
|
result = self._callFUT(tzstring)
|
||||||
|
self.assertEqual(result.utcoffset(None),
|
||||||
|
datetime.timedelta(hours=-1, minutes=0))
|
||||||
|
|
||||||
class Test_parse_date(unittest.TestCase):
|
class Test_parse_date(unittest.TestCase):
|
||||||
def _callFUT(self, datestring):
|
def _callFUT(self, datestring):
|
||||||
from ..iso8601 import parse_date
|
from ..iso8601 import parse_date
|
||||||
|
Reference in New Issue
Block a user