Skip to content

fix(timestamp): detect & convert microsecond/nanosecond epochs - #43

Merged
slaveofcode merged 1 commit into
developfrom
fix/timestamp-sub-second-units
Jul 27, 2026
Merged

fix(timestamp): detect & convert microsecond/nanosecond epochs#43
slaveofcode merged 1 commit into
developfrom
fix/timestamp-sub-second-units

Conversation

@slaveofcode

Copy link
Copy Markdown
Owner

Problem

The timestamp converter errored on high-resolution epoch values like 1784694237438743460 (19-digit nanoseconds) with "Could not parse that as a date or Unix timestamp." — any numeric string over 10 digits was assumed to be milliseconds, and 1.78×10¹⁸ ms is far outside JS Date's ±271k-year range.

Fix

parseTimestamp now infers the unit from digit length (≈10 = seconds, ≈13 = ms, ≈16 = µs, ≈19 = ns) and normalizes to milliseconds. The seconds/millisecond cutoffs (≤10, ≤13) are unchanged, so all prior behavior is preserved. The UI shows a "Detected numeric input as Unix nanoseconds" note so the interpretation is explicit.

17846942374387434602026-07-22T04:23:57Z.

Tests

+4 cases (micro/nanosecond parsing, the reported value, detectNumericUnit). Full suite 433 pass; lint clean.

Previously parseTimestamp treated any numeric string longer than 10 digits
as milliseconds, so a 19-digit nanosecond value (e.g. 1784694237438743460)
overflowed Date's range and failed with 'Could not parse that as a date or
Unix timestamp.'

Now the unit is inferred from digit length — ~10 = seconds, ~13 = ms,
~16 = µs, ~19 = ns — and normalized to milliseconds. The UI surfaces the
detected unit so the interpretation is explicit. Seconds/millis cutoffs are
unchanged, so existing behavior is preserved.

Adds coverage for micro/nanosecond parsing and detectNumericUnit.
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 27, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
goodwebtools 48c5ef4 Jul 27 2026, 08:21 AM

@slaveofcode
slaveofcode merged commit 247a529 into develop Jul 27, 2026
2 checks passed
@slaveofcode
slaveofcode deleted the fix/timestamp-sub-second-units branch July 27, 2026 08:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant