diff options
author | Michael Twomey <michael.twomey@fieldaware.com> | 2013-10-17 18:11:14 +0100 |
---|---|---|
committer | Michael Twomey <michael.twomey@fieldaware.com> | 2013-10-17 18:11:14 +0100 |
commit | 9c3f2b8518d5641973cd5ad45e26c0a980506bf9 (patch) | |
tree | 66965fab0c0ff8f1d18fe3fedf2d293f1afa3c6c /iso8601/iso8601.py | |
parent | 0f9f3ea4a92619cccd35481c0fdb112f29a1b570 (diff) | |
download | pyiso8601-9c3f2b8518d5641973cd5ad45e26c0a980506bf9.tar.gz |
Fix microsecond rounding issues
Thanks to nielsenb@jetfuse.net
Fixes #2
Diffstat (limited to 'iso8601/iso8601.py')
-rw-r--r-- | iso8601/iso8601.py | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/iso8601/iso8601.py b/iso8601/iso8601.py index a121e2e..b979f02 100644 --- a/iso8601/iso8601.py +++ b/iso8601/iso8601.py @@ -13,6 +13,7 @@ from datetime import ( timedelta, tzinfo ) +from decimal import Decimal import logging import sys import re @@ -28,7 +29,8 @@ else: # Adapted from http://delete.me.uk/2005/03/iso8601.html -ISO8601_REGEX = re.compile(r""" +ISO8601_REGEX = re.compile( + r""" (?P<year>[0-9]{4}) (-{0,1}(?P<month>[0-9]{1,2})){1} (-{0,1}(?P<day>[0-9]{1,2})){1} @@ -159,7 +161,7 @@ def parse_date(datestring, default_timezone=UTC): tz = parse_timezone(groups, default_timezone=default_timezone) - groups["second_fraction"] = int(float("0.%s" % to_int(groups, "second_fraction", default_to_zero=True)) * 1e6) + groups["second_fraction"] = int(Decimal("0.%s" % to_int(groups, "second_fraction", default_to_zero=True)) * Decimal("1000000.0")) try: return datetime( |