Skip to content

Commit 354bef0

Browse files
committed
fix localtime
1 parent 299b7d6 commit 354bef0

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/tomli/_parser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -634,9 +634,9 @@ def parse_value( # noqa: C901
634634
except ValueError as e:
635635
raise suffixed_err(src, pos, "Invalid date or datetime") from e
636636
return pos, datetime_obj
637-
localtime_match = re_time.RE_LOCALTIME.match(src, pos)
637+
localtime_match = re_time.RE_LOCALTIME.match(src[pos:])
638638
if localtime_match:
639-
return localtime_match.end(), re_time.match_to_localtime(localtime_match)
639+
return pos + len(localtime_match.group(0)), re_time.match_to_localtime(localtime_match)
640640

641641
# Integers and "normal" floats.
642642
# The regex will greedily match any type starting with a decimal

src/tomli/_re_time.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from datetime import date, datetime, time, timedelta, timezone, tzinfo
22
import re
33

4-
RE_LOCALTIME = re.compile(r"([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])(?:\.([0-9]{1,6})[0-9]*)?")
4+
RE_LOCALTIME = re.compile(r"([01]\d|2[0-3]):([0-5]\d):([0-5]\d)(\.(\d\d?\d?\d?\d?\d?)\d*)?")
5+
56
RE_DATETIME_YMD = re.compile(r"""(\d\d\d\d)-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])""")
67
RE_DATETIME_TIME = re.compile(
78
r"""([Tt ]([01]\d|2[0-3]):([0-5]\d):([0-5]\d)(\.(\d\d?\d?\d?\d?\d?)\d*)?)?"""
@@ -85,6 +86,6 @@ def match_to_localtime(match):
8586
hour_str = match.group(1)
8687
minute_str = match.group(2)
8788
sec_str = match.group(3)
88-
micros_str = match.group(4)
89-
micros = int(micros_str.ljust(6, "0")) if micros_str else 0
89+
micros_str = match.group(5)
90+
micros = int(micros_str + '0' * max(0, 6 - len(micros_str))) if micros_str else 0
9091
return time(int(hour_str), int(minute_str), int(sec_str), micros)

0 commit comments

Comments
 (0)