8279185: Support for IsoFields in JapaneseDate/MinguoDate/ThaiBuddhistDate

Reviewed-by: joehw, rriggs
This commit is contained in:
Naoto Sato 2022-05-23 16:20:52 +00:00
parent ac274c4ca6
commit ef7a9f8170
13 changed files with 272 additions and 38 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -546,7 +546,10 @@ public final class IsoFields {
if (isSupportedBy(temporal) == false) {
throw new UnsupportedTemporalTypeException("Unsupported field: WeekBasedYear");
}
return super.rangeRefinedBy(temporal);
var range = super.rangeRefinedBy(temporal);
var chronoRange = Chronology.from(temporal).range(YEAR);
return ValueRange.of(Math.max(range.getMinimum(), chronoRange.getMinimum()),
Math.min(range.getMaximum(), chronoRange.getMaximum()));
}
@SuppressWarnings("unchecked")
@Override
@ -591,12 +594,6 @@ public final class IsoFields {
private static final int[] QUARTER_DAYS = {0, 90, 181, 273, 0, 91, 182, 274};
private static void ensureIso(TemporalAccessor temporal) {
if (isIso(temporal) == false) {
throw new DateTimeException("Resolve requires IsoChronology");
}
}
private static ValueRange getWeekRange(LocalDate date) {
int wby = getWeekBasedYear(date);
return ValueRange.of(1, getWeekRange(wby));
@ -731,7 +728,14 @@ public final class IsoFields {
}
}
static boolean isIso(TemporalAccessor temporal) {
return Chronology.from(temporal).equals(IsoChronology.INSTANCE);
private static void ensureIso(TemporalAccessor temporal) {
if (!isIso(temporal)) {
throw new DateTimeException("Resolve requires ISO based chronology: " +
Chronology.from(temporal));
}
}
private static boolean isIso(TemporalAccessor temporal) {
return Chronology.from(temporal).isIsoBased();
}
}