src/share/classes/java/time/chrono/MinguoChronology.java

Print this page

        

*** 52,73 **** * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ ! package java.time.calendar; import static java.time.temporal.ChronoField.YEAR; import java.io.Serializable; import java.time.DateTimeException; import java.time.LocalDate; ! import java.time.temporal.Chrono; import java.time.temporal.ChronoField; - import java.time.temporal.ChronoLocalDate; - import java.time.temporal.Era; - import java.time.temporal.ISOChrono; import java.time.temporal.TemporalAccessor; import java.time.temporal.ValueRange; import java.util.Arrays; import java.util.List; import java.util.Locale; --- 52,72 ---- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ ! package java.time.chrono; import static java.time.temporal.ChronoField.YEAR; import java.io.Serializable; + import java.time.Clock; import java.time.DateTimeException; + import java.time.Instant; import java.time.LocalDate; ! import java.time.ZoneId; import java.time.temporal.ChronoField; import java.time.temporal.TemporalAccessor; import java.time.temporal.ValueRange; import java.util.Arrays; import java.util.List; import java.util.Locale;
*** 75,85 **** /** * The Minguo calendar system. * <p> * This chronology defines the rules of the Minguo calendar system. * This calendar system is primarily used in the Republic of China, often known as Taiwan. ! * Dates are aligned such that {@code 0001-01-01 (Minguo)} is {@code 1911-01-01 (ISO)}. * <p> * The fields are defined as follows: * <p><ul> * <li>era - There are two eras, the current 'Republic' (ERA_ROC) and the previous era (ERA_BEFORE_ROC). * <li>year-of-era - The year-of-era for the current era increases uniformly from the epoch at year one. --- 74,84 ---- /** * The Minguo calendar system. * <p> * This chronology defines the rules of the Minguo calendar system. * This calendar system is primarily used in the Republic of China, often known as Taiwan. ! * Dates are aligned such that {@code 0001-01-01 (Minguo)} is {@code 1912-01-01 (ISO)}. * <p> * The fields are defined as follows: * <p><ul> * <li>era - There are two eras, the current 'Republic' (ERA_ROC) and the previous era (ERA_BEFORE_ROC). * <li>year-of-era - The year-of-era for the current era increases uniformly from the epoch at year one.
*** 98,123 **** * <h3>Specification for implementors</h3> * This class is immutable and thread-safe. * * @since 1.8 */ ! public final class MinguoChrono extends Chrono<MinguoChrono> implements Serializable { /** * Singleton instance for the Minguo chronology. */ ! public static final MinguoChrono INSTANCE = new MinguoChrono(); /** * The singleton instance for the era ROC. */ ! public static final Era<MinguoChrono> ERA_ROC = MinguoEra.ROC; /** * The singleton instance for the era BEFORE_ROC. */ ! public static final Era<MinguoChrono> ERA_BEFORE_ROC = MinguoEra.BEFORE_ROC; /** * Serialization version. */ private static final long serialVersionUID = 1039765215346859963L; --- 97,122 ---- * <h3>Specification for implementors</h3> * This class is immutable and thread-safe. * * @since 1.8 */ ! public final class MinguoChronology extends Chronology implements Serializable { /** * Singleton instance for the Minguo chronology. */ ! public static final MinguoChronology INSTANCE = new MinguoChronology(); /** * The singleton instance for the era ROC. */ ! public static final Era ERA_ROC = MinguoEra.ROC; /** * The singleton instance for the era BEFORE_ROC. */ ! public static final Era ERA_BEFORE_ROC = MinguoEra.BEFORE_ROC; /** * Serialization version. */ private static final long serialVersionUID = 1039765215346859963L;
*** 127,137 **** static final int YEARS_DIFFERENCE = 1911; /** * Restricted constructor. */ ! private MinguoChrono() { } /** * Resolve singleton. * --- 126,136 ---- static final int YEARS_DIFFERENCE = 1911; /** * Restricted constructor. */ ! private MinguoChronology() { } /** * Resolve singleton. *
*** 143,154 **** //----------------------------------------------------------------------- /** * Gets the ID of the chronology - 'Minguo'. * <p> ! * The ID uniquely identifies the {@code Chrono}. ! * It can be used to lookup the {@code Chrono} using {@link #of(String)}. * * @return the chronology ID - 'Minguo' * @see #getCalendarType() */ @Override --- 142,153 ---- //----------------------------------------------------------------------- /** * Gets the ID of the chronology - 'Minguo'. * <p> ! * The ID uniquely identifies the {@code Chronology}. ! * It can be used to lookup the {@code Chronology} using {@link #of(String)}. * * @return the chronology ID - 'Minguo' * @see #getCalendarType() */ @Override
*** 159,169 **** /** * Gets the calendar type of the underlying calendar system - 'roc'. * <p> * The calendar type is an identifier defined by the * <em>Unicode Locale Data Markup Language (LDML)</em> specification. ! * It can be used to lookup the {@code Chrono} using {@link #of(String)}. * It can also be used as part of a locale, accessible via * {@link Locale#getUnicodeLocaleType(String)} with the key 'ca'. * * @return the calendar system type - 'roc' * @see #getId() --- 158,168 ---- /** * Gets the calendar type of the underlying calendar system - 'roc'. * <p> * The calendar type is an identifier defined by the * <em>Unicode Locale Data Markup Language (LDML)</em> specification. ! * It can be used to lookup the {@code Chronology} using {@link #of(String)}. * It can also be used as part of a locale, accessible via * {@link Locale#getUnicodeLocaleType(String)} with the key 'ca'. * * @return the calendar system type - 'roc' * @see #getId()
*** 173,198 **** return "roc"; } //----------------------------------------------------------------------- @Override ! public ChronoLocalDate<MinguoChrono> date(int prolepticYear, int month, int dayOfMonth) { return new MinguoDate(LocalDate.of(prolepticYear + YEARS_DIFFERENCE, month, dayOfMonth)); } @Override ! public ChronoLocalDate<MinguoChrono> dateYearDay(int prolepticYear, int dayOfYear) { return new MinguoDate(LocalDate.ofYearDay(prolepticYear + YEARS_DIFFERENCE, dayOfYear)); } @Override ! public ChronoLocalDate<MinguoChrono> date(TemporalAccessor temporal) { if (temporal instanceof MinguoDate) { return (MinguoDate) temporal; } return new MinguoDate(LocalDate.from(temporal)); } //----------------------------------------------------------------------- /** * Checks if the specified year is a leap year. * <p> --- 172,237 ---- return "roc"; } //----------------------------------------------------------------------- @Override ! public MinguoDate date(int prolepticYear, int month, int dayOfMonth) { return new MinguoDate(LocalDate.of(prolepticYear + YEARS_DIFFERENCE, month, dayOfMonth)); } @Override ! public MinguoDate dateYearDay(int prolepticYear, int dayOfYear) { return new MinguoDate(LocalDate.ofYearDay(prolepticYear + YEARS_DIFFERENCE, dayOfYear)); } @Override ! public MinguoDate date(TemporalAccessor temporal) { if (temporal instanceof MinguoDate) { return (MinguoDate) temporal; } return new MinguoDate(LocalDate.from(temporal)); } + @Override + public MinguoDate date(Era era, int yearOfEra, int month, int dayOfMonth) { + return date(prolepticYear(era, yearOfEra), month, dayOfMonth); + + } + + @Override + public MinguoDate dateYearDay(Era era, int yearOfEra, int dayOfYear) { + return dateYearDay(prolepticYear(era, yearOfEra), dayOfYear); + } + + @Override + public MinguoDate dateNow() { + return dateNow(Clock.systemDefaultZone()); + } + + @Override + public MinguoDate dateNow(ZoneId zone) { + return dateNow(Clock.system(zone)); + } + + @Override + public MinguoDate dateNow(Clock clock) { + return date(LocalDate.now(clock)); + } + + @Override + public ChronoLocalDateTime<MinguoDate> localDateTime(TemporalAccessor temporal) { + return (ChronoLocalDateTime<MinguoDate>)super.localDateTime(temporal); + } + + @Override + public ChronoZonedDateTime<MinguoDate> zonedDateTime(TemporalAccessor temporal) { + return (ChronoZonedDateTime<MinguoDate>)super.zonedDateTime(temporal); + } + + @Override + public ChronoZonedDateTime<MinguoDate> zonedDateTime(Instant instant, ZoneId zone) { + return (ChronoZonedDateTime<MinguoDate>)super.zonedDateTime(instant, zone); + } //----------------------------------------------------------------------- /** * Checks if the specified year is a leap year. * <p>
*** 203,231 **** * @param prolepticYear the proleptic-year to check, not validated for range * @return true if the year is a leap year */ @Override public boolean isLeapYear(long prolepticYear) { ! return ISOChrono.INSTANCE.isLeapYear(prolepticYear + YEARS_DIFFERENCE); } @Override ! public int prolepticYear(Era<MinguoChrono> era, int yearOfEra) { if (era instanceof MinguoEra == false) { throw new DateTimeException("Era must be MinguoEra"); } return (era == MinguoEra.ROC ? yearOfEra : 1 - yearOfEra); } @Override ! public Era<MinguoChrono> eraOf(int eraValue) { return MinguoEra.of(eraValue); } @Override ! public List<Era<MinguoChrono>> eras() { ! return Arrays.<Era<MinguoChrono>>asList(MinguoEra.values()); } //----------------------------------------------------------------------- @Override public ValueRange range(ChronoField field) { --- 242,270 ---- * @param prolepticYear the proleptic-year to check, not validated for range * @return true if the year is a leap year */ @Override public boolean isLeapYear(long prolepticYear) { ! return IsoChronology.INSTANCE.isLeapYear(prolepticYear + YEARS_DIFFERENCE); } @Override ! public int prolepticYear(Era era, int yearOfEra) { if (era instanceof MinguoEra == false) { throw new DateTimeException("Era must be MinguoEra"); } return (era == MinguoEra.ROC ? yearOfEra : 1 - yearOfEra); } @Override ! public Era eraOf(int eraValue) { return MinguoEra.of(eraValue); } @Override ! public List<Era> eras() { ! return Arrays.<Era>asList(MinguoEra.values()); } //----------------------------------------------------------------------- @Override public ValueRange range(ChronoField field) {