Skip to content

Add TC39 Temporal Duration magnitude validation in constructor and DurationFromObject #326

@coderabbitai

Description

@coderabbitai

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

  1. 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.
  2. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions