Date/DateTime arithmetic outside 0001-9999 returns null instead of throwing
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 72/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ệ
- javascript
- Lĩnh vực
- backend
Hướng nghiên cứu
Read src/elm/arithmetic.ts, especially Add, Subtract, and finalizeArithmeticResult, then inspect the Date and DateTime range checks in the datatypes. Reproduce the listed date arithmetic cases and compare them with the numeric overflow behavior. Done means out-of-range Date and DateTime results throw while numeric overflow still returns null, with the existing tests updated or added to cover both.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Adding a quantity to (or subtracting it from) a Date or DateTime returns null when the result falls outside the supported range (0001-01-01 to 9999-12-31). The specification and the official tests expect a run-time error, at least for years.
library DateArithmeticOutOfRange version '1.0.0'
define AddYearsDateTime: DateTime(2005, 10, 10) + 8000 years // null (cql-tests DateTimeAddInvalidYears)
define SubtractYearsDateTime: DateTime(2005, 10, 10) - 2005 years // null (cql-tests DateTimeSubtractInvalidYears)
define AddYearsDate: @2005-10-10 + 8000 years // null
define AddMonthDateTime: @9999-12-15T00:00:00.000Z + 1 month // null
define AddDayDate: @9999-12-31 + 1 day // null
define SubtractDayDate: @0001-01-01 - 1 day // null
define AddDayDateIsNull: (@9999-12-31 + 1 day) is null // true
Expected: a run-time error.
- Author's Guide, Date/Time arithmetic, calendar semantics for
year: "If the resulting year is out of range, an error is thrown." - cql-tests marks
DateTimeAddInvalidYearsandDateTimeSubtractInvalidYearsasinvalid="true"("The date time addition results in a year greater than the accepted range."). The spec-test runner currently treats such tests as no-ops (#351), so the difference does not show up there. - The reference Java/Kotlin engine throws for all six expressions ("The year: 10005 falls above the accepted bounds of 0001-9999.").
For months and days the text does not repeat the rule. We assume it applies too, since the result is not a representable Date or DateTime. The specification returns null only for numeric overflow and for successor/predecessor at the bounds of the type.
A null here changes the logic silently: the last line shows that the overflowed value is indistinguishable from a missing one.
Cause: Add and Subtract pass every result through finalizeArithmeticResult, which returns null when overflowsOrUnderflows is true:
This is correct for Integer, Long, Decimal and Quantity (Appendix B, Add: "If the result of the addition cannot be represented (i.e. arithmetic overflow), the result is null."), but it also applies to Date and DateTime operands. A possible fix is to throw for Date/DateTime results outside the range and keep null for the numeric types.
Side note: DateTime.add has a misplaced parenthesis, result.after(MAX_DATETIME_VALUE || result.before(MIN_DATETIME_VALUE)), so its own underflow check never runs:
It has no visible effect today, because Add/Subtract check the result again.
Environment:
- cql-execution 3.3.2 and 4.0.0-beta.1 (same results);
- ELM from
@cqframework/cql5.8.0 (npm); - Node 24, Windows 11, TZ=UTC.
Found while differential testing date operators across engines.
- Ngôn ngữ chính
- JavaScript
- Star
- 86
- Fork
- 40
- 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
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Không có hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của cqframework/cql-execution
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
cqframework/cql-execution#410 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
cqframework/cql-execution#407 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
cqframework/cql-execution#406 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
cqframework/cql-execution#414 ·
-
Length throws TypeError when its null operand is not an As expression (e.g. an expression reference)Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 65/100
cqframework/cql-execution#412 ·
Tất cả issue của cqframework/cql-execution
Issue tương tự
-
Mend: dependency security vulnerability
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
ManageIQ/manageiq-ui-service#2259 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 73/100
electerious/Ackee#411 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[bug] 提瓦特记事本原石检测框宽度较窄Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
babalae/bettergi-scripts-list#3905 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug] "Configure Colota" opens Colota with "Invalid configuration: No configuration data in URL"Đang mở
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 87/100
dedicatedcode/reitti#1445 ·
Maintainer thường phản hồi trong vòng 1 ngày