Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/builtins/core/plain_year_month.rs
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,11 @@ impl PlainYearMonth {
// 4. Let calendar be yearMonth.[[Calendar]].
// 5. Let fields be ISODateToFields(calendar, yearMonth.[[ISODate]], year-month).
// 6. Let partialYearMonth be ? PrepareCalendarFields(calendar, temporalYearMonthLike, « year, month, month-code », « », partial).
if fields.is_empty() {
return Err(
TemporalError::r#type().with_message("plainYearMonth fields cannot be empty")
);
}
// 7. Set fields to CalendarMergeFields(calendar, fields, partialYearMonth).
// 8. Let resolvedOptions be ? GetOptionsObject(options).
// 9. Let overflow be ? GetTemporalOverflowOption(resolvedOptions).
Expand Down Expand Up @@ -942,19 +947,17 @@ mod tests {
); // assert month code has changed
assert_eq!(with_month_code.iso_month(), 5); // month is changed as well

// Day
let fields = YearMonthCalendarFields::new();
let with_day = base.with(fields, None).unwrap();
assert_eq!(with_day.iso_year(), 2025); // year is not changed
assert_eq!(with_day.iso_month(), 3); // month is not changed
assert_eq!(with_day.iso.day, 1); // day is ignored

// All
let fields = YearMonthCalendarFields::new().with_year(2001).with_month(2);
let with_all = base.with(fields, None).unwrap();
assert_eq!(with_all.iso_year(), 2001); // year is changed
assert_eq!(with_all.iso_month(), 2); // month is changed
assert_eq!(with_all.iso.day, 1); // day is ignored

// Empty fields -> throws error
let fields = YearMonthCalendarFields::new();
let empty = base.with(fields, None);
assert!(empty.is_err());
}

#[test]
Expand Down