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
@ -76,6 +76,7 @@ import java.time.format.DateTimeFormatterBuilder;
import java.time.format.ResolverStyle;
import java.time.format.TextStyle;
import java.time.temporal.ChronoField;
import java.time.temporal.IsoFields;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalField;
import java.time.temporal.TemporalQueries;
@ -736,7 +737,7 @@ public interface Chronology extends Comparable<Chronology> {
* @throws DateTimeException if any of the values are out of range
* @since 9
*/
public default long epochSecond(int prolepticYear, int month, int dayOfMonth,
default long epochSecond(int prolepticYear, int month, int dayOfMonth,
int hour, int minute, int second, ZoneOffset zoneOffset) {
Objects.requireNonNull(zoneOffset, "zoneOffset");
HOUR_OF_DAY.checkValidValue(hour);
@ -765,11 +766,38 @@ public interface Chronology extends Comparable<Chronology> {
* @throws DateTimeException if any of the values are out of range
* @since 9
*/
public default long epochSecond(Era era, int yearOfEra, int month, int dayOfMonth,
default long epochSecond(Era era, int yearOfEra, int month, int dayOfMonth,
int hour, int minute, int second, ZoneOffset zoneOffset) {
Objects.requireNonNull(era, "era");
return epochSecond(prolepticYear(era, yearOfEra), month, dayOfMonth, hour, minute, second, zoneOffset);
}
/**
* Checks if this chronology is ISO based.
* <p>
* An ISO based chronology has the same basic structure as the {@link IsoChronology
* ISO chronology}, i.e., the chronology has the same number of months, the number
* of days in each month, and day-of-year and leap years are the same as ISO chronology.
* It also supports the concept of week-based-year of ISO chronology.
* For example, the {@link MinguoChronology Minguo}, {@link ThaiBuddhistChronology
* ThaiThaiBuddhist} and {@link JapaneseChronology Japanese} chronologies are ISO based.
*
* @implSpec
* The default implementation returns {@code false}.
*
* @return {@code true} only if all the fields of {@link IsoFields} are supported by
* this chronology. Otherwise, returns {@code false}.
* @see IsoChronology
* @see JapaneseChronology
* @see MinguoChronology
* @see ThaiBuddhistChronology
* @see IsoFields
* @since 19
*/
default boolean isIsoBased() {
return false;
}
//-----------------------------------------------------------------------
/**
* Compares this chronology to another chronology.

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
@ -87,6 +87,7 @@ import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.format.ResolverStyle;
import java.time.temporal.ChronoField;
import java.time.temporal.IsoFields;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalField;
import java.time.temporal.ValueRange;
@ -677,6 +678,20 @@ public final class IsoChronology extends AbstractChronology implements Serializa
return Period.of(years, months, days);
}
//-----------------------------------------------------------------------
/**
* {@code IsoChronology} is an ISO based chronology, which supports fields
* in {@link IsoFields}, such as {@link IsoFields#DAY_OF_QUARTER DAY_OF_QUARTER}
* and {@link IsoFields#QUARTER_OF_YEAR QUARTER_OF_YEAR}.
* @see IsoFields
* @return {@code true}
* @since 19
*/
@Override
public boolean isIsoBased() {
return true;
}
//-----------------------------------------------------------------------
/**
* Writes the Chronology using a

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2021, 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
@ -76,6 +76,7 @@ import java.time.Year;
import java.time.ZoneId;
import java.time.format.ResolverStyle;
import java.time.temporal.ChronoField;
import java.time.temporal.IsoFields;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalAdjusters;
import java.time.temporal.TemporalField;
@ -504,6 +505,20 @@ public final class JapaneseChronology extends AbstractChronology implements Seri
return dateYearDay(era, yoe, doy); // smart is same as strict
}
//-----------------------------------------------------------------------
/**
* {@code JapaneseChronology} is an ISO based chronology, which supports fields
* in {@link IsoFields}, such as {@link IsoFields#DAY_OF_QUARTER DAY_OF_QUARTER}
* and {@link IsoFields#QUARTER_OF_YEAR QUARTER_OF_YEAR}.
* @see IsoFields
* @return {@code true}
* @since 19
*/
@Override
public boolean isIsoBased() {
return true;
}
//-----------------------------------------------------------------------
/**
* Writes the Chronology using a

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
@ -465,13 +465,13 @@ public final class JapaneseDate
@Override
public long getLong(TemporalField field) {
if (field instanceof ChronoField) {
if (field instanceof ChronoField cf) {
// same as ISO:
// DAY_OF_WEEK, DAY_OF_MONTH, EPOCH_DAY, MONTH_OF_YEAR, PROLEPTIC_MONTH, YEAR
//
// calendar specific fields
// DAY_OF_YEAR, YEAR_OF_ERA, ERA
switch ((ChronoField) field) {
switch (cf) {
case ALIGNED_DAY_OF_WEEK_IN_MONTH:
case ALIGNED_DAY_OF_WEEK_IN_YEAR:
case ALIGNED_WEEK_OF_MONTH:

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
@ -69,6 +69,7 @@ import java.time.LocalDate;
import java.time.ZoneId;
import java.time.format.ResolverStyle;
import java.time.temporal.ChronoField;
import java.time.temporal.IsoFields;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalField;
import java.time.temporal.ValueRange;
@ -335,6 +336,20 @@ public final class MinguoChronology extends AbstractChronology implements Serial
return (MinguoDate) super.resolveDate(fieldValues, resolverStyle);
}
//-----------------------------------------------------------------------
/**
* {@code MinguoChronology} is an ISO based chronology, which supports fields
* in {@link IsoFields}, such as {@link IsoFields#DAY_OF_QUARTER DAY_OF_QUARTER}
* and {@link IsoFields#QUARTER_OF_YEAR QUARTER_OF_YEAR}.
* @see IsoFields
* @return {@code true}
* @since 19
*/
@Override
public boolean isIsoBased() {
return true;
}
//-----------------------------------------------------------------------
/**
* Writes the Chronology using a

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2021, 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
@ -69,6 +69,7 @@ import java.time.LocalDate;
import java.time.ZoneId;
import java.time.format.ResolverStyle;
import java.time.temporal.ChronoField;
import java.time.temporal.IsoFields;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalField;
import java.time.temporal.ValueRange;
@ -335,6 +336,20 @@ public final class ThaiBuddhistChronology extends AbstractChronology implements
return (ThaiBuddhistDate) super.resolveDate(fieldValues, resolverStyle);
}
//-----------------------------------------------------------------------
/**
* {@code ThaiBuddhistChronology} is an ISO based chronology, which supports fields
* in {@link IsoFields}, such as {@link IsoFields#DAY_OF_QUARTER DAY_OF_QUARTER}
* and {@link IsoFields#QUARTER_OF_YEAR QUARTER_OF_YEAR}.
* @see IsoFields
* @return {@code true}
* @since 19
*/
@Override
public boolean isIsoBased() {
return true;
}
//-----------------------------------------------------------------------
/**
* Writes the Chronology using a