Skip to content

Commit

Permalink
Merge branch 'main' into chinese-fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
atcupps committed Aug 1, 2023
2 parents 2b67c84 + 4f9f66b commit ec9517b
Show file tree
Hide file tree
Showing 176 changed files with 33,559 additions and 9 deletions.
36 changes: 35 additions & 1 deletion components/calendar/src/any_calendar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ macro_rules! match_cal_and_date {
(&Self::Chinese(ref $cal_matched), &AnyDateInner::Chinese(ref $date_matched)) => $e,
(&Self::Persian(ref $cal_matched), &AnyDateInner::Persian(ref $date_matched)) => $e,
(&Self::Coptic(ref $cal_matched), &AnyDateInner::Coptic(ref $date_matched)) => $e,
(&Self::Roc(ref $cal_matched), &AnyDateInner::Roc(ref $date_matched)) => $e,
(&Self::Iso(ref $cal_matched), &AnyDateInner::Iso(ref $date_matched)) => $e,
_ => panic!(
"Found AnyCalendar with mixed calendar type {} and date type {}!",
Expand Down Expand Up @@ -266,6 +267,9 @@ impl Calendar for AnyCalendar {
(Self::Persian(c), &mut AnyDateInner::Persian(ref mut d)) => {
c.offset_date(d, offset.cast_unit())
}
(Self::Roc(c), &mut AnyDateInner::Roc(ref mut d)) => {
c.offset_date(d, offset.cast_unit())
}
// This is only reached from misuse of from_raw, a semi-internal api
#[allow(clippy::panic)]
(_, d) => panic!(
Expand Down Expand Up @@ -349,6 +353,9 @@ impl Calendar for AnyCalendar {
) => c1
.until(d1, d2, c2, largest_unit, smallest_unit)
.cast_unit(),
(Self::Roc(c1), Self::Roc(c2), AnyDateInner::Roc(d1), AnyDateInner::Roc(d2)) => c1
.until(d1, d2, c2, largest_unit, smallest_unit)
.cast_unit(),
(
Self::Coptic(c1),
Self::Coptic(c2),
Expand Down Expand Up @@ -735,7 +742,12 @@ impl AnyCalendarKind {
b"ethiopic" => AnyCalendarKind::Ethiopian,
b"ethioaa" => AnyCalendarKind::EthiopianAmeteAlem,
b"persian" => AnyCalendarKind::Persian,
_ => return None,
b"roc" => AnyCalendarKind::Roc,
_ => {
// Log a warning when a calendar value is passed in but doesn't match any calendars
DataError::custom("bcp47_bytes did not match any calendars").with_debug_context(x);
return None;
}
})
}
/// Construct from a BCP-47 [`Value`]
Expand Down Expand Up @@ -765,7 +777,11 @@ impl AnyCalendarKind {
AnyCalendarKind::EthiopianAmeteAlem
} else if *x == value!("persian") {
AnyCalendarKind::Persian
} else if *x == value!("roc") {
AnyCalendarKind::Roc
} else {
// Log a warning when a calendar value is passed in but doesn't match any calendars
DataError::custom("bcp47_value did not match any calendars").with_display_context(x);
return None;
})
}
Expand Down Expand Up @@ -1000,6 +1016,18 @@ impl IntoAnyCalendar for Iso {
}
}

impl IntoAnyCalendar for Roc {
fn to_any(self) -> AnyCalendar {
AnyCalendar::Roc(Roc)
}
fn to_any_cloned(&self) -> AnyCalendar {
AnyCalendar::Roc(Roc)
}
fn date_to_any(&self, d: &Self::DateInner) -> AnyDateInner {
AnyDateInner::Roc(*d)
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down Expand Up @@ -1085,6 +1113,7 @@ mod tests {
let japanese = AnyCalendar::new(AnyCalendarKind::Japanese);
let japanext = AnyCalendar::new(AnyCalendarKind::JapaneseExtended);
let persian = AnyCalendar::new(AnyCalendarKind::Persian);
let roc = AnyCalendar::new(AnyCalendarKind::Roc);
let buddhist = Ref(&buddhist);
let coptic = Ref(&coptic);
let ethiopian = Ref(&ethiopian);
Expand All @@ -1095,6 +1124,7 @@ mod tests {
let japanese = Ref(&japanese);
let japanext = Ref(&japanext);
let persian = Ref(&persian);
let roc = Ref(&roc);

single_test_roundtrip(buddhist, "be", 100, "M03", 1);
single_test_roundtrip(buddhist, "be", 2000, "M03", 1);
Expand Down Expand Up @@ -1249,5 +1279,9 @@ mod tests {
1,
CalendarError::UnknownMonthCode("M9".parse().unwrap(), "Persian"),
);

single_test_roundtrip(roc, "roc", 10, "M05", 3);
single_test_roundtrip(roc, "roc-inverse", 15, "M01", 10);
single_test_roundtrip(roc, "roc", 100, "M10", 30);
}
}
2 changes: 1 addition & 1 deletion components/calendar/src/roc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl Calendar for Roc {
if year <= 0 {
return Err(CalendarError::OutOfRange);
}
1 - (year + ROC_ERA_OFFSET)
1 - year + ROC_ERA_OFFSET
} else {
return Err(CalendarError::UnknownEra(era.0, self.debug_name()));
};
Expand Down
4 changes: 4 additions & 0 deletions components/datetime/data/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
"datetime/japanese/datesymbols@1",
"datetime/japanext/datelengths@1",
"datetime/japanext/datesymbols@1",
"datetime/roc/datelengths@1",
"datetime/roc/datesymbols@1",
"datetime/persian/datelengths@1",
"datetime/persian/datesymbols@1",
"datetime/skeletons@1",
"datetime/timelengths@1",
"datetime/timesymbols@1",
Expand Down
20 changes: 20 additions & 0 deletions components/datetime/data/data/macros.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ec9517b

Please sign in to comment.