Skip to content

Commit 9538e52

Browse files
committed
fix for calculus pisanus
see issue #461
1 parent 3376a37 commit 9538e52

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

i18n/src/main/java/net/time4j/history/HistoricIntegerElement.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ public Integer parse(
255255
if (parsedResult != null) {
256256
parsedResult.with(StdHistoricalElement.YEAR_OF_DISPLAY, yod);
257257
}
258-
} else if (Math.abs(yoe - yod) <= 1) { // check for plausibility
258+
} else if (Math.abs(yoe - yod) <= 2) { // plausibility check (delta 2 necessary for calculus pisanus)
259259
value = yoe;
260260
} else { // now we have something else - let the formatter process the rest
261261
value = yod;

i18n/src/test/java/net/time4j/history/EraFormatTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,4 +480,25 @@ public void parseFrance() throws ParseException {
480480
is(PlainDate.of(1565, 4, 3)));
481481
}
482482

483+
@Test
484+
public void printPisa() {
485+
ChronoFormatter<PlainDate> formatter =
486+
ChronoFormatter.ofDatePattern("G-yyyy-MM-dd", PatternType.CLDR, new Locale("en", "IT", "PISA")).with(Leniency.STRICT);
487+
assertThat(
488+
formatter.format(PlainDate.of(1700, 1, 30)),
489+
is("AD-1698/1700-01-30"));
490+
}
491+
492+
@Test
493+
public void parsePisa() throws ParseException {
494+
ChronoFormatter<PlainDate> formatter =
495+
ChronoFormatter.ofDatePattern("G-yyyy-MM-dd", PatternType.CLDR, new Locale("en", "IT", "PISA")).with(Leniency.STRICT);
496+
assertThat(
497+
formatter.parse("AD-1698/1700-01-30"),
498+
is(PlainDate.of(1700, 1, 30)));
499+
assertThat(
500+
formatter.parse("AD-1700-01-30"),
501+
is(PlainDate.of(1700, 1, 30)));
502+
}
503+
483504
}

0 commit comments

Comments
 (0)