Skip to content

Commit da727d5

Browse files
committed
Allow 3 and 6 decimal floats and update valid format string
1 parent 4252da7 commit da727d5

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

adafruit_datetime.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,13 +1224,13 @@ def fromtimestamp(cls, timestamp, tz=None):
12241224
@classmethod
12251225
def fromisoformat(cls, date_string, tz=None):
12261226
"""Return a datetime object constructed from an ISO date format.
1227-
Valid format is YYYY-MM-DD[*HH[:MM[:SS[.fff[fff]]]][+HH:MM[:SS[.ffffff]]]]
1227+
Valid format is YYYY-MM-DD[*HH[:MM[:SS[.fff[fff]]]]]
12281228
12291229
"""
12301230
match = _re.match(
12311231
(
1232-
r"([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])(T([0-9][0-9]))?(:([0-9][0-9]))"
1233-
r"?(:([0-9][0-9]))?(\.[0-9][0-9][0-9][0-9][0-9][0-9])?"
1232+
r"([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])(T([0-9][0-9]))?(:([0-9][0-9]))?"
1233+
r"(:([0-9][0-9]))?(\.([0-9][0-9][0-9])([0-9][0-9][0-9])?)?"
12341234
),
12351235
date_string,
12361236
)
@@ -1239,7 +1239,12 @@ def fromisoformat(cls, date_string, tz=None):
12391239
hh = int(match.group(5)) if match.group(5) else 0
12401240
mm = int(match.group(5)) if match.group(7) else 0
12411241
ss = int(match.group(9)) if match.group(9) else 0
1242-
us = round((float("0" + match.group(10)) if match.group(10) else 0) * 1e6)
1242+
us = 0
1243+
print(match.group(10))
1244+
if match.group(11):
1245+
us += int(match.group(11)) * 1000
1246+
if match.group(12):
1247+
us += int(match.group(12))
12431248
result = cls(
12441249
y,
12451250
m,

0 commit comments

Comments
 (0)