Skip to content

Commit 9632e9c

Browse files
committed
refactor: improve timestamp precision handling in Firebase event parsing
1 parent cbadc1a commit 9632e9c

1 file changed

Lines changed: 4 additions & 6 deletions

File tree

  • src/firebase_functions/private

src/firebase_functions/private/util.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ def second_timestamp_conversion(time: str) -> _dt.datetime:
371371

372372
class PrecisionTimestamp(_enum.Enum):
373373
"""
374-
The status of a token.
374+
Timestamp precision levels supported by Firebase event timestamp parsing.
375375
"""
376376

377377
NANOSECONDS = "NANOSECONDS"
@@ -385,15 +385,13 @@ def __str__(self) -> str:
385385

386386

387387
def get_precision_timestamp(time: str) -> PrecisionTimestamp:
388-
"""Return a bool which indicates if the timestamp is in nanoseconds"""
388+
"""Return the precision used by a Firebase event timestamp."""
389389
if "." not in time:
390390
return PrecisionTimestamp.SECONDS
391391

392392
_, s_fraction = time.split(".", 1)
393-
fraction_match = _re.match(r"\d+", s_fraction)
394-
if fraction_match is None:
395-
raise ValueError("Invalid timestamp")
396-
393+
if not (fraction_match := _re.match(r"\d+", s_fraction)):
394+
raise ValueError(f"Invalid timestamp format: {time}")
397395
s_fraction = fraction_match.group()
398396

399397
# If the fraction is more than 6 digits long, it's a nanosecond timestamp

0 commit comments

Comments
 (0)