arrow
arrow copied to clipboard
Fix _TIMESTAMP_RE to match single-digit timestamps
Summary
Fix _TIMESTAMP_RE to correctly match single-digit timestamps like epoch 0.
Problem
The current regex pattern is:
_TIMESTAMP_RE = re.compile(r"^\-?\d+\.?\d+$")
This requires \d+ (one or more digits) on both sides of the optional decimal point. For single-digit values:
\d+greedily matches the only digit\.?optionally matches nothing\d+requires at least one more digit, but input is exhausted → no match
import re
pattern = re.compile(r"^\-?\d+\.?\d+$")
pattern.match("0") # None ← should match
pattern.match("1") # None ← should match
pattern.match("-1") # None ← should match
pattern.match("10") # Match ← works for 2+ digits
This means arrow.get("0", "X") raises ParserMatchError instead of parsing epoch 0.
Fix
Change the trailing \d+ to \d* so the fractional part is fully optional:
_TIMESTAMP_RE = re.compile(r"^\-?\d+\.?\d*$")