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

未关闭 适合新手
#23 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
74/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
领域
tooling

调研方向

从 parseDuration()(位于 src/parser.ts)开始:小数位在读取单位指示符之前就已经被捕获,但只有 unit === 'S' 分支会存储它们。阅读 secondsFraction 的 AST 类型以及 stringifier 的 duration 分支,看看小数字段会如何被传递,然后决定是在 H/M/日期单位上保留小数,还是抛出 ParseError。该 issue 的 repro.mjs 片段就是检查:用四个输入运行它,并确认输出要么保留小数,要么是显式错误,而不是静默截断。在现有 duration 用例旁边添加 parser 测试。

由索引模型根据 Issue 内容生成。

描述

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/

主要语言
TypeScript
星标
26
派生
5
PR 合并指标
30 天内没有已合并 PR

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

taskade/temporal-parser 的其他 Issue

查看 taskade/temporal-parser 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。