Skip to content

Commit 84bab65

Browse files
Change LeapStatus::StandardAfterLeap to ::LeapBase (#7701)
1 parent 6bd65a1 commit 84bab65

File tree

5 files changed

+59
-11
lines changed

5 files changed

+59
-11
lines changed

components/calendar/src/cal/east_asian_traditional.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,11 @@ impl<R: Rules> Calendar for EastAsianTraditional<R> {
760760
/// leap months. For example, in a year where an intercalary month is added after the second
761761
/// month, the month codes for ordinal months 1, 2, 3, 4, 5 would be "M01", "M02", "M02L", "M03", "M04".
762762
fn month(&self, date: &Self::DateInner) -> types::MonthInfo {
763-
types::MonthInfo::new(self, date.0)
763+
let mut m = types::MonthInfo::new(self, date.0);
764+
if date.0.year().packed.leap_month() == Some(m.ordinal + 1) {
765+
m.leap_status = types::LeapStatus::LeapBase;
766+
}
767+
m
764768
}
765769

766770
/// The calendar-specific day-of-month represented by `date`

components/calendar/src/cal/hebrew.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,10 +325,17 @@ impl Calendar for Hebrew {
325325

326326
fn month(&self, date: &Self::DateInner) -> MonthInfo {
327327
let mut m = MonthInfo::new(self, date.0);
328-
#[allow(deprecated)]
328+
// Even though the leap month is modeled as M05L,
329+
// the actual leap base is M06.
329330
if m.number() == 6 && m.ordinal == 7 {
330-
m.leap_status = LeapStatus::StandardAfterLeap;
331-
m.formatting_code = Month::leap(6).code();
331+
m.leap_status = LeapStatus::LeapBase;
332+
#[allow(deprecated)]
333+
{
334+
// This is an ICU4X invention, it's not needed by
335+
// formatting anymore, but we keep producing it
336+
// for now.
337+
m.formatting_code = Month::leap(6).code();
338+
}
332339
}
333340
m
334341
}

components/calendar/src/types.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -493,12 +493,14 @@ pub enum LeapStatus {
493493
Normal,
494494
/// A leap month.
495495
Leap,
496-
/// A month that is not itself considered a leap month, but might
497-
/// have special formatting because it occurs after a leap month.
498-
///
499-
/// An example of this is the Hebrew month "Adar", which is called
500-
/// "Adar II" when it follows the leap month "Adar I".
501-
StandardAfterLeap,
496+
/// A standard month that has a corresponding leap month
497+
/// in the same year.
498+
///
499+
/// "Corresponding" is used in a formatting sense here:
500+
/// even though the Hebrew "Adar I" is `M05L`, the
501+
/// `LeapBase` will be `M06` (not `M05`), so formatting
502+
/// knows to produce "Adar II".
503+
LeapBase,
502504
}
503505

504506
impl Month {

components/datetime/src/pattern/names.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3781,7 +3781,13 @@ impl RawDateTimeNamesBorrowed<'_> {
37813781
}
37823782
MonthNames::LeapLinear(leap_linear) => {
37833783
let num_months = leap_linear.len() / 2;
3784-
if month.leap_status() != LeapStatus::Normal {
3784+
if month.leap_status() == LeapStatus::Leap {
3785+
leap_linear.get(month_index + num_months)
3786+
} else if month.leap_status() == LeapStatus::LeapBase
3787+
&& month.number() < month.ordinal
3788+
{
3789+
// Detects Hebrew (base after leap) vs Chinese (base before leap).
3790+
// In Hebrew, we use leap names for LeapBase months.
37853791
leap_linear.get(month_index + num_months)
37863792
} else if month_index < num_months {
37873793
leap_linear.get(month_index)

components/datetime/tests/fixtures/tests/components.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,35 @@
5454
}
5555
}
5656
},
57+
{
58+
"input": {
59+
"value": "2023-03-10T14:15:07.123",
60+
"options": {
61+
"components": {
62+
"weekday": "long",
63+
"month": "long",
64+
"day": "two-digit-day-of-month",
65+
"era": "long",
66+
"year": "numeric",
67+
"hour": "numeric",
68+
"minute": "numeric",
69+
"second": "numeric"
70+
},
71+
"semantic": {
72+
"dateFields": "YMDE",
73+
"length": "long",
74+
"timePrecision": "second",
75+
"yearStyle": "withEra"
76+
}
77+
}
78+
},
79+
"output": {
80+
"values": {
81+
"en-u-ca-chinese-hc-h23": "Friday, Second Month 19, 2023(gui-mao) at 14:15:07",
82+
"zh-u-ca-chinese-hc-h23": "2023癸卯年二月19星期五 14:15:07"
83+
}
84+
}
85+
},
5786
{
5887
"input": {
5988
"value": "2023-03-23T14:15:07.123",

0 commit comments

Comments
 (0)