Skip to content

Incorrect range check in Calendar::month_day_from_fields #688

@ptomato

Description

@ptomato

According to the Temporal specification (CalendarMonthDayToISOReferenceDate), ISO-calendar PlainMonthDays should only use the year field to determine if the month and day exist, not to check the range.

I think this is probably due to the use of self.date_from_fields() to carry out the RegulateISODate step in the spec, which does not check the year range. So it appears to be a regression from #492.

This JS snippet throws in Boa and V8, but should not:

new Temporal.PlainMonthDay(1, 1).with({ year: -271821 })

temporal_rs reproducers:

let iso = IsoDate::new_unchecked(1972, 1, 1);
let md = PlainMonthDay::new_unchecked(iso, Calendar::ISO);
let partial = CalendarFields {
    year: Some(-271821),
    ..Default::default()
};
let result = md.with(partial, None).expect("should not throw");

let fields = CalendarFields {
    year: Some(-271821),
    month: Some(1),
    day: Some(1),
    ..Default::default()
};
Calendar::ISO.month_day_from_fields(fields, Overflow::Constrain).expect("should not throw");

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions