diff options
author | jortel <devnull@localhost> | 2009-12-07 18:00:31 +0000 |
---|---|---|
committer | jortel <devnull@localhost> | 2009-12-07 18:00:31 +0000 |
commit | e660374a393d7ea0d6b8eaa31196333902245bf4 (patch) | |
tree | 85d1e2964afc49f1f53d602cbcec3edd2162b084 | |
parent | 5f542259241a3c5cbcddd00c072fe44fa2fbf4ca (diff) | |
download | suds-e660374a393d7ea0d6b8eaa31196333902245bf4.tar.gz |
Trim microsecond to 999999 when bigger to comply with python datetime.datetime restriction.
-rw-r--r-- | suds/__init__.py | 2 | ||||
-rw-r--r-- | suds/sax/date.py | 12 | ||||
-rw-r--r-- | tests/builtin.py | 16 |
3 files changed, 25 insertions, 5 deletions
diff --git a/suds/__init__.py b/suds/__init__.py index ae5d8eb..772a563 100644 --- a/suds/__init__.py +++ b/suds/__init__.py @@ -29,7 +29,7 @@ import sys # __version__ = '0.3.8' -__build__="(beta) R618-20091204" +__build__="(beta) R619-20091207" # # Exceptions diff --git a/suds/sax/date.py b/suds/sax/date.py index e895cdd..67bce5e 100644 --- a/suds/sax/date.py +++ b/suds/sax/date.py @@ -221,16 +221,22 @@ class Time: def __second(self, s): """ Parse the seconds and microseconds. + The microseconds are truncated to 999999 due to a restriction in + the python datetime.datetime object. @param s: A string representation of the seconds. @type s: str @return: Tuple of (sec,ms) @rtype: tuple. """ part = s.split('.') - if len(part) == 1: - return (int(part[0]), None) + if len(part) > 1: + second = int(part[0]) + ms = int(part[1]) + if ms > 999999: ms = 999999 else: - return (int(part[0]), int(part[1])) + second = int(part[0]) + ms = None + return (second, ms) def __offset(self, s): """ diff --git a/tests/builtin.py b/tests/builtin.py index ce96f92..8ebcf78 100644 --- a/tests/builtin.py +++ b/tests/builtin.py @@ -72,13 +72,27 @@ class TimeTest(TestCase): t = xtime.translate(s) self.assertEqual(t, ref) + def testSimpleWithShortMicrosecond(self): + ref = dt.time(10, 30, 22, 34) + s = '%.2d:%.2d:%.2d.%4.d' % (ref.hour, ref.minute, ref.second, ref.microsecond) + xtime = Time() + t = xtime.translate(s) + self.assertEqual(t, ref) + def testSimpleWithMicrosecond(self): - ref = dt.time(10, 30, 22, 454) + ref = dt.time(10, 30, 22, 999999) s = '%.2d:%.2d:%.2d.%4.d' % (ref.hour, ref.minute, ref.second, ref.microsecond) xtime = Time() t = xtime.translate(s) self.assertEqual(t, ref) + def testSimpleWithLongMicrosecond(self): + ref = dt.time(10, 30, 22, 999999) + s = '%.2d:%.2d:%.2d.%4.d' % (ref.hour, ref.minute, ref.second, int('999999999')) + xtime = Time() + t = xtime.translate(s) + self.assertEqual(t, ref) + def testPositiveTimezone(self): self.equalsTimezone(6) |