Skip to content

Fix up eras, correctly expose arithmetic year#424

Merged
Manishearth merged 4 commits intoboa-dev:mainfrom
Manishearth:extended-year
Jul 20, 2025
Merged

Fix up eras, correctly expose arithmetic year#424
Manishearth merged 4 commits intoboa-dev:mainfrom
Manishearth:extended-year

Conversation

@Manishearth
Copy link
Copy Markdown
Contributor

@Manishearth Manishearth commented Jul 19, 2025

This does a bunch of fixes to the era code:

  • Updates the list of eras to the latest proposal-intl-era-monthcode list
  • Correctly exposes .year() as arithmetic year
  • Allows specifying both year and era/eraYear as long as they match
  • Adds a test for arithmetic year calculation
  • Switches over to using None eras for calendars that do not canonically have them

Fixes #423

@Manishearth Manishearth requested a review from nekevss July 19, 2025 22:03
Copy link
Copy Markdown
Member

@nekevss nekevss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me overall. I did have one question regarding an error message, but it's not necessarily blocking.

}
AnyCalendarKind::Japanese if *era_alias == tinystr!(19, "mejei") => {
Some(era::MEJEI_ERA)
AnyCalendarKind::Japanese if *era_alias == tinystr!(19, "meiji") => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😱 nice catch!

Comment thread src/builtins/core/calendar/types.rs Outdated
let calculated_arith = era_info.arithmetic_year_for(era_year);
if calculated_arith != arith {
return Err(
TemporalError::range().with_message("Conflicting era/eraYear info")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: shouldn't this be for conflicting year and eraYear values?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, yes, correct. will fix when I'm back at a computer

Copy link
Copy Markdown
Contributor Author

@Manishearth Manishearth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops my comments never got posted

(Some(year), None, None) => Ok(Self {
era: partial
.calendar
.get_calendar_default_era()
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in theory here we should be able to just pass down None; ICU4X treats None as "default era"

})
}
(None, Some(era), Some(era_year)) => {
(maybe_year, Some(era), Some(era_year)) => {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not yet handle cases like (year, era, eraYear = none) or (year, era = None, eraYear). They're a bit more nonsensical; I'm not sure if we should be doing anything here.

// or a RangeError exception if the fields are sufficient but their values are internally inconsistent
// within the calendar (e.g., when fields such as [[Month]] and [[MonthCode]] have conflicting non-unset values). For example:
if let Some(arith) = maybe_year {
let calculated_arith = era_info.arithmetic_year_for(era_year);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note that this deliberately compares arithmetic years instead of trying for the default era: (2019, reiwa, 1) is an okay thing to specify.

Comment thread src/builtins/core/calendar/types.rs Outdated
let calculated_arith = era_info.arithmetic_year_for(era_year);
if calculated_arith != arith {
return Err(
TemporalError::range().with_message("Conflicting era/eraYear info")
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, yes, correct. will fix when I'm back at a computer

@Manishearth Manishearth merged commit 19e34b3 into boa-dev:main Jul 20, 2025
8 checks passed
@Manishearth Manishearth deleted the extended-year branch August 2, 2025 06:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

EraYear::try_from_partial_date needs to be able to handle fully-loaded partial dates

2 participants