Skip to content

Commit

Permalink
fixes #620
Browse files Browse the repository at this point in the history
  • Loading branch information
barsch committed Sep 1, 2013
1 parent e553f73 commit 821129f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
15 changes: 13 additions & 2 deletions obspy/core/tests/test_utcdatetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ def test_richComparisonNonNumericTypes(self):
self.assertFalse(obj >= dt)
self.assertFalse(obj > dt)

def test_timezone_aware_datetime(self):
def test_datetime_with_timezone(self):
"""
UTCDateTime from timezone-aware datetime.datetime
Expand Down Expand Up @@ -907,11 +907,12 @@ def test_abs(self):
dt = UTCDateTime(1969, 12, 31, 23, 59, 59, 500000)
self.assertEquals(abs(dt), 0.5)

def test_issue620_timezone_parsing(self):
def test_string_with_timezone(self):
"""
Test that all valid ISO time zone specifications are parsed properly
http://en.wikipedia.org/wiki/ISO_8601#Time_offsets_from_UTC
"""
# positive
t = UTCDateTime("2013-09-01T12:34:56Z")
time_strings = \
["2013-09-01T14:34:56+02", "2013-09-01T14:34:56+02:00",
Expand All @@ -921,6 +922,16 @@ def test_issue620_timezone_parsing(self):
for time_string in time_strings:
self.assertEqual(t, UTCDateTime(time_string))

# negative
t = UTCDateTime("2013-09-01T12:34:56Z")
time_strings = \
["2013-09-01T10:34:56-02", "2013-09-01T10:34:56-02:00",
"2013-09-01T10:34:56-0200", "2013-09-01T10:19:56-02:15",
"2013-09-01T12:34:56-00:00", "2013-09-01T12:34:56-00",
"2013-09-01T12:34:56-0000"]
for time_string in time_strings:
self.assertEqual(t, UTCDateTime(time_string))


def suite():
return unittest.makeSuite(UTCDateTimeTestCase, 'test')
Expand Down
20 changes: 13 additions & 7 deletions obspy/core/utcdatetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,13 +410,19 @@ def _parseISO8601(value):
# check for time zone information
# note that the zone designator is the actual offset from UTC and
# does not include any information on daylight saving time
delta = 0
if time.count('+') == 1:
(time, tz) = time.split('+')
delta = -1 * (int(tz[0:2]) * 60 * 60 + int(tz[2:]) * 60)
elif time.count('-') == 1:
(time, tz) = time.split('-')
delta = int(tz[0:2]) * 60 * 60 + int(tz[2:]) * 60
if time.count('+') == 1 and '+' in time[-6:]:
(time, tz) = time.rsplit('+')
delta = -1
elif time.count('-') == 1 and '-' in time[-6:]:
(time, tz) = time.rsplit('-')
delta = 1
else:
delta = 0
if delta:
tz = tz.replace(':', '')
while len(tz) < 3:
tz += '0'
delta = delta * (int(tz[0:2]) * 60 * 60 + int(tz[2:]) * 60)
# split microseconds
ms = 0
if '.' in time:
Expand Down

0 comments on commit 821129f

Please sign in to comment.