Summary
Add TC39 Temporal specification magnitude validation for Temporal.Duration components.
Background
Per the TC39 Temporal spec, duration components must satisfy the following constraints:
- Calendar units (years, months, weeks): absolute value must be < 2³² (4,294,967,296)
- Normalized time: when all time components are normalized to seconds, the absolute value must be < 2⁵³
Currently, TGocciaTemporalDurationValue (constructor) and DurationFromObject accept and truncate component values to Int64 without enforcing these bounds. Out-of-spec durations can be constructed without error, which violates the specification.
What needs to be done
- In
TGocciaTemporalDurationValue.Create (constructor), validate that the absolute values of years, months, and weeks are each < 2³², and that the normalized seconds value is < 2⁵³. Throw a RangeError if any constraint is violated.
- Apply the same validation in
DurationFromObject before constructing the TGocciaTemporalDurationValue instance.
Why this was deferred
The arithmetic in downstream helpers (DurationEndDate, AddMonthsToDate, DurationTotal) is safe for spec-compliant inputs. The gap is that upstream validation is not yet implemented. This was flagged during PR #324 review and scoped out as a follow-up.
References
Summary
Add TC39 Temporal specification magnitude validation for
Temporal.Durationcomponents.Background
Per the TC39 Temporal spec, duration components must satisfy the following constraints:
Currently,
TGocciaTemporalDurationValue(constructor) andDurationFromObjectaccept and truncate component values toInt64without enforcing these bounds. Out-of-spec durations can be constructed without error, which violates the specification.What needs to be done
TGocciaTemporalDurationValue.Create(constructor), validate that the absolute values ofyears,months, andweeksare each < 2³², and that the normalized seconds value is < 2⁵³. Throw aRangeErrorif any constraint is violated.DurationFromObjectbefore constructing theTGocciaTemporalDurationValueinstance.Why this was deferred
The arithmetic in downstream helpers (
DurationEndDate,AddMonthsToDate,DurationTotal) is safe for spec-compliant inputs. The gap is that upstream validation is not yet implemented. This was flagged during PR #324 review and scoped out as a follow-up.References