Skip to content

Commit a9186ff

Browse files
committed
Fix Japanese calendar year 0 (unicode-org#5006)
Fixes unicode-org#4968 I'd like to make a release for this one because it's a one-line change and we're already working on a patch release. (cherry picked from commit ad65b6d)
1 parent c892e80 commit a9186ff

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- `icu_datetime`
66
- Fix incorrect assertion in week-of-year formatting (https://github.com/unicode-org/icu4x/issues/4977)
7+
- Fix Japanese calendar Gregorian era year 0 (https://github.com/unicode-org/icu4x/issues/4968)
78

89
## icu4x 1.5 (May 28, 2024)
910

components/calendar/src/japanese.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ impl Japanese {
665665
// for japanext, meiji for japanese),
666666
// In such a case, we instead fall back to Gregorian era codes
667667
if date < start {
668-
if date.year < 0 {
668+
if date.year <= 0 {
669669
(1 - date.year, tinystr!(16, "bce"))
670670
} else {
671671
(date.year, tinystr!(16, "ce"))
@@ -826,7 +826,11 @@ mod tests {
826826
assert_eq!(
827827
date, reconstructed,
828828
"Failed to roundtrip with {era:?}, {year}, {month}, {day}"
829-
)
829+
);
830+
831+
// Extra coverage for https://github.com/unicode-org/icu4x/issues/4968
832+
assert_eq!(reconstructed.year().era, era);
833+
assert_eq!(reconstructed.year().number, year);
830834
}
831835

832836
fn single_test_roundtrip_ext(

0 commit comments

Comments
 (0)