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

Đang mở Phù hợp với người mới
#23 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
74/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
node.js, typescript
Lĩnh vực
tooling

Hướng nghiên cứu

Bắt đầu tại parseDuration() trong src/parser.ts: các chữ số phần phân số đã được thu thập trước khi chỉ định đơn vị được đọc, nhưng chỉ nhánh unit === 'S' mới lưu chúng. Đọc kiểu AST cho secondsFraction và nhánh duration của stringifier để xem một trường phân số sẽ được truyền qua như thế nào, rồi quyết định xem nên giữ phần phân số trên H/M/đơn vị ngày hay ném một ParseError. Đoạn repro.mjs của issue là bước kiểm tra: chạy nó với bốn đầu vào và xác nhận đầu ra hoặc giữ nguyên phần phân số hoặc là một lỗi rõ ràng, không phải cắt bỏ âm thầm. Thêm test parser bên cạnh các ca duration hiện có.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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/

Ngôn ngữ chính
TypeScript
Star
26
Fork
5
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của taskade/temporal-parser

Tất cả issue của taskade/temporal-parser

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.