fix: rate times parse leniently via new Date (local time, 2026-02-30, T24:00)

Open
#349 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
25/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
rust, typescript
Domain
data

Research direction

Start in src/rate.ts at toIsoString, which handles the date-only regex branch and falls back to new Date(text). Run the repro strings from the issue under TZ=UTC and TZ=America/New_York to confirm the current behaviour. Done means the accepted formats are restricted as proposed, bad input throws RangeError, and tests cover the repros, with the CHANGELOG and upgrade guide updated for 0.5. The proposal is a breaking change, the Rust port is included, and the thread has no decision yet, so check with maintainers first.

Written by the indexing model from the issue text.

Description

toIsoString in src/rate.ts keeps any string matching ^\d{4}-\d\d-\d\d$ as a date unchecked, and passes everything else to new Date(text). So the times a Rate, a RateTable and a lookup take (asOf, availableAt, validUntil, a query's asOf, isExpired(now), isAvailable(at)) accept whatever the JavaScript engine's date parser accepts. Some of those strings mean different instants on different machines, and some aren't dates at all.

Repros

These were run against src/rate.ts on main with node 24, first with TZ=UTC and then with TZ=America/New_York:

import { exchangeRate, toIsoString } from './src/rate.js';

toIsoString('2026-11-06T15:00:00');        // TZ=UTC: '2026-11-06T15:00:00.000Z'
                                           // TZ=America/New_York: '2026-11-06T20:00:00.000Z'
toIsoString('2026-02-30');                 // '2026-02-30' (kept as a date, unchecked)
toIsoString('2026-11-06T24:00:00Z');       // '2026-11-07T00:00:00.000Z'
toIsoString('2026-11-06t15:00:00z');       // '2026-11-06T15:00:00.000Z' (lowercase t and z)
toIsoString('+002026-11-06T15:00:00Z');    // '2026-11-06T15:00:00.000Z' (expanded year)
toIsoString('2026-11-06T15:00:00.9999Z');  // '2026-11-06T15:00:00.999Z' (digits past ms truncated)
toIsoString('2026-11-06 15:00:00Z');       // '2026-11-06T15:00:00.000Z' (space for T)
toIsoString('Nov 6 2026 15:00 GMT');       // '2026-11-06T15:00:00.000Z' (not ISO 8601)
toIsoString('2026-11');                    // '2026-11-01T00:00:00.000Z' (a month, read as an instant)

exchangeRate('EUR', 'USD', '1.1', { validUntil: '2026-02-30' }).isExpired('2026-03-01'); // true
  • Offset-less date-times are read in the machine's local time zone. The same rate data gives different asOf, availableAt and validUntil instants, and so different lookups and expiries, depending on TZ.
  • Impossible dates (2026-02-30) are stored as given and compared as strings.
  • T24:00, lowercase t/z, a space for T, expanded years, non-ISO forms and partial dates (2026-11) are accepted by V8's parser, and other engines may differ.
  • Fractions past milliseconds are truncated silently.

Proposal

Accept only YYYY-MM-DD (a real calendar day), or YYYY-MM-DDTHH:MM[:SS[.sss]] followed by Z or ±HH:MM. Throw RangeError for anything else; a Date object stays accepted as it is. The Rust port in rust/ will parse this strictly from the start, and document it as a deliberate divergence until ducat does the same.

This is a behaviour change: input that ducat 0.4 accepts would throw. It belongs in 0.5, with a CHANGELOG entry under Changed and a note in the upgrade guide.

Dominant language
TypeScript
Stars
0
Forks
0
Avg merge
35m
Merged PRs (30d)
242

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from public/ducat

All issues in public/ducat

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.