Date and DateTime selectors accept invalid components (Date(2023, 2, 29), month 13, day 32); later operations give NaN

未关闭
#414 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
68/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
领域
backend, testing

调研方向

Start in src/elm/datetime.ts, where the issue identifies the Date and DateTime expressions as passing evaluated components to datatype constructors without validation; then inspect the DT.Date and DT.DateTime constructors and existing date string validation. Run the relevant date and datetime tests, and add coverage for invalid computed components such as a non-leap-year February 29, month 13, and day 32. Done means these selectors no longer produce invalid date values that later yield NaN.

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

描述

The Date and DateTime selectors accept components that do not form a calendar date, such as 29 February in a non-leap year, month 13 or day 32. The resulting value then breaks later operations, producing NaN.

library InvalidDateComponents version '1.0.0'

define Feb29NonLeap: Date(2023, 2, 29)                                  // 2023-02-29
define Month13: Date(2023, 13, 1)                                       // 2023-13-01
define Day32: Date(2023, 1, 32)                                         // 2023-01-32
define DateTimeFeb29NonLeap: DateTime(2023, 2, 29, 0, 0, 0, 0, 0)       // 2023-02-29T00:00:00.000+00:00
define Feb29PlusOneDay: Date(2023, 2, 29) + 1 day                       // a Date that prints as 0NaN-NaN-NaN
define Feb29EqualsMar01: Date(2023, 2, 29) = @2023-03-01                // false
define DaysFeb28ToFeb29: days between @2023-02-28 and Date(2023, 2, 29) // Uncertainty with NaN bounds

Expected: these selectors should not return a Date or DateTime value.

  • The reference Java/Kotlin engine throws for each of them ("Invalid date 'February 29' as '2023' is not a leap year", "Invalid date: month must be a number between 1 and 12, got 13", "day of month must be a number between 1 and 31, got 32").
  • The translator rejects the equivalent literal: @2023-02-29 gives "Invalid date-time input (2023-02-29)".
  • Appendix B (Date, DateTime) states the rule for missing components only. It does not say whether an invalid component gives an error or null, so null would also be a defensible choice. A value that is not a date, and that later turns into NaN, is not.

The selectors can be fed from computed components (for example Date(year from X, month from X, 28 + n)), so this is not limited to literals.

Cause: the ELM Date and DateTime expressions pass the evaluated components to the datatype constructors without validation:

https://github.com/cqframework/cql-execution/blob/e87e3fa8a3802c69a760b2583d2306d7c66d9899/src/elm/datetime.ts#L50-L73

(DateTime at L8-L48). A possible fix is to validate the components there (or in DT.Date/DT.DateTime), for example with luxon's DateTime.fromObject(...).isValid (the string parser already relies on luxon's isValid in isValidDateStringFormat).

Environment:

  • cql-execution 3.3.2 and 4.0.0-beta.1 (same results);
  • ELM from @cqframework/cql 5.8.0 (npm);
  • Node 24, Windows 11, TZ=UTC.

Found while differential testing date operators across engines. Related: #413 (out-of-range results of date arithmetic).

主要语言
JavaScript
星标
86
派生
40
PR 合并指标
30 天内没有已合并 PR

环境准备

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

从这里开始

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

cqframework/cql-execution 的其他 Issue

查看 cqframework/cql-execution 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

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