summaryrefslogtreecommitdiff
path: root/util.py
diff options
context:
space:
mode:
authorAnthon van der Neut <anthon@mnt.org>2022-01-03 09:22:25 +0100
committerAnthon van der Neut <anthon@mnt.org>2022-01-03 09:22:25 +0100
commit25f75a2cbbc0425b722d85117cd611f498f48cea (patch)
tree448eb5d177d88a7c86ac9bfb4c3884513ad43367 /util.py
parent285a927e0b675d7b67d7d893e3b86862784fb0fb (diff)
downloadruamel.yaml-25f75a2cbbc0425b722d85117cd611f498f48cea.tar.gz
fix issue 414 dateime fraction >= 99999950.17.20
Diffstat (limited to 'util.py')
-rw-r--r--util.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/util.py b/util.py
index f3a96a1..9ff51bd 100644
--- a/util.py
+++ b/util.py
@@ -68,6 +68,8 @@ def create_timestamp(
year, month, day, t, hour, minute, second, fraction, tz, tz_sign, tz_hour, tz_minute
):
# type: (Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any) -> Any
+ # create a timestamp from match against timestamp_regexp
+ MAX_FRAC = 999999
year = int(year)
month = int(month)
day = int(day)
@@ -76,24 +78,31 @@ def create_timestamp(
hour = int(hour)
minute = int(minute)
second = int(second)
+ frac = 0
if fraction:
- frac = 0
frac_s = fraction[:6]
while len(frac_s) < 6:
frac_s += '0'
frac = int(frac_s)
if len(fraction) > 6 and int(fraction[6]) > 4:
frac += 1
- fraction = frac
+ if frac > MAX_FRAC:
+ fraction = 0
+ else:
+ fraction = frac
else:
fraction = 0
delta = None
if tz_sign:
tz_hour = int(tz_hour)
tz_minute = int(tz_minute) if tz_minute else 0
- delta = datetime.timedelta(hours=tz_hour, minutes=tz_minute)
+ delta = datetime.timedelta(
+ hours=tz_hour, minutes=tz_minute, seconds=1 if frac > MAX_FRAC else 0
+ )
if tz_sign == '-':
delta = -delta
+ elif frac > MAX_FRAC:
+ delta = -datetime.timedelta(seconds=1)
# should do something else instead (or hook this up to the preceding if statement
# in reverse
# if delta is None: