parseTemporal silently drops fractional parts on non-second duration units (e.g. `PT0.5H` -> `PT0H`)

Offen Anfängerfreundlich
#23 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
74/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
node.js, typescript
Bereich
tooling

Rechercherichtung

Beginne bei parseDuration() in src/parser.ts: Die Bruchziffern werden bereits erfasst, bevor die Einheitenbezeichnung gelesen wird, aber nur der Zweig unit === 'S' speichert sie. Lies den AST-Typ für secondsFraction und den Dauer-Zweig des Stringifiers, um zu sehen, wie ein Bruchteil-Feld durchgereicht würde, und entscheide dann, ob Brüche bei H/M/Datums-Einheiten erhalten bleiben sollen oder ein ParseError ausgelöst werden soll. Der repro.mjs-Schnipsel des Issues ist die Prüfung: Führe ihn mit den vier Eingaben aus und bestätige, dass die Ausgabe entweder brucherhaltend oder ein expliziter Fehler ist, kein stilles Abschneiden. Füge Parser-Tests zusammen mit den bestehenden Dauer-Fällen hinzu.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

parseTemporal accepts decimal fractions (. or ,) on any duration unit without throwing, but only preserves the fraction for seconds (S), silently truncating fractional hours, minutes, and date units to integers.

Playground: https://lxcid.com/tools/temporal-playground/?expr=PT0.5H

npm install @taskade/[email protected]
node repro.mjs
// repro.mjs
import { parseTemporal, stringifyTemporal } from "@taskade/temporal-parser";

for (const input of ["PT0.5H", "PT1.5M", "PT0,5H", "P1.5D"]) {
  const ast = parseTemporal(input);
  console.log(input, ast, stringifyTemporal(ast));
}

console.log(Temporal.Duration.from(parseTemporal("PT0.5H")).toString());
console.log(Temporal.Duration.from("PT0.5H").toString());

Actual output:

PT0.5H { kind: 'Duration', hours: 0, raw: 'PT0.5H', annotations: [] } PT0H
PT1.5M { kind: 'Duration', minutes: 1, raw: 'PT1.5M', annotations: [] } PT1M
PT0,5H { kind: 'Duration', hours: 0, raw: 'PT0,5H', annotations: [] } PT0H
P1.5D { kind: 'Duration', days: 1, raw: 'P1.5D', annotations: [] } P1D
PT0S
PT30M

Expected output:

ISO 8601 allows a decimal fraction on the lowest-order duration unit (and TC39 Temporal accepts fractions on H, M, and S), so parseTemporal should either preserve fractional non-second components in the AST or throw a ParseError when a fraction appears on an unsupported unit, rather than returning truncated integer fields (hours: 0 / "PT0H").

In src/parser.ts, parseDuration() consumes . / , and the fractional digits into fraction before reading the unit designator, then only stores fraction in the unit === 'S' branch (dur.secondsFraction = fraction) and ignores it in every other unit branch.

Versions: @taskade/[email protected] (main commit 729b967), Node.js v26.13.0 on Linux x64.

Credit: https://ucsbplse.github.io/

Vorherrschende Sprache
TypeScript
Sterne
26
Forks
5
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus taskade/temporal-parser

Alle Issues in taskade/temporal-parser

Ähnliche Issues

Weitere Issues zu TypeScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.