diff options
author | Gerhard Weis <g.weis@uq.edu.au> | 2021-12-13 10:05:41 +1000 |
---|---|---|
committer | Gerhard Weis <g.weis@uq.edu.au> | 2021-12-13 10:05:41 +1000 |
commit | 89f80896e074c072e6014b6196cd768d9e75d0b0 (patch) | |
tree | f1ba8d8fb9bd29dd51f8ea3a4fc4e3a1eadba528 /src/isodate/isotime.py | |
parent | 924975890471f9baf3f0a86b277770fff299e106 (diff) | |
download | isodate-89f80896e074c072e6014b6196cd768d9e75d0b0.tar.gz |
- round down microseconds (in case precision is higher)
Diffstat (limited to 'src/isodate/isotime.py')
-rw-r--r-- | src/isodate/isotime.py | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/isodate/isotime.py b/src/isodate/isotime.py index 3e2bb46..470c5b6 100644 --- a/src/isodate/isotime.py +++ b/src/isodate/isotime.py @@ -6,7 +6,7 @@ It supports all basic and extended formats including time zone specifications as described in the ISO standard. """ import re -from decimal import Decimal +from decimal import Decimal, ROUND_FLOOR from datetime import time from isodate.isostrf import strftime, TIME_EXT_COMPLETE, TZ_EXT @@ -102,8 +102,9 @@ def parse_time(timestring): int(groups["tzmin"] or 0), ) if "second" in groups: - # round to microseconds if fractional seconds are more precise - second = Decimal(groups["second"]).quantize(Decimal(".000001")) + second = Decimal(groups["second"]).quantize( + Decimal(".000001"), rounding=ROUND_FLOOR + ) microsecond = (second - int(second)) * int(1e6) # int(...) ... no rounding # to_integral() ... rounding @@ -116,7 +117,9 @@ def parse_time(timestring): ) if "minute" in groups: minute = Decimal(groups["minute"]) - second = (minute - int(minute)) * 60 + second = Decimal((minute - int(minute)) * 60).quantize( + Decimal(".000001"), rounding=ROUND_FLOOR + ) microsecond = (second - int(second)) * int(1e6) return time( int(groups["hour"]), |