arrow icon indicating copy to clipboard operation
arrow copied to clipboard

Fix _TIMESTAMP_RE to match single-digit timestamps

Open bysiber opened this issue 9 months ago • 0 comments

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:

  1. \d+ greedily matches the only digit
  2. \.? optionally matches nothing
  3. \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*$")

bysiber avatar Feb 20 '26 05:02 bysiber