< prev index next >

src/share/classes/java/util/JapaneseImperialCalendar.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 2005, 2013, 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 * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this --- 1,7 ---- /* ! * Copyright (c) 2005, 2019, 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 * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this
*** 48,57 **** --- 48,58 ---- * 0 N/A N/A * 1 Meiji 1868-01-01 midnight local time * 2 Taisho 1912-07-30 midnight local time * 3 Showa 1926-12-25 midnight local time * 4 Heisei 1989-01-08 midnight local time + * 5 NewEra 2019-05-01 midnight local time * ------------------------------------------------------ * </tt></pre> * * <p><code>ERA</code> value 0 specifies the years before Meiji and * the Gregorian year values are used. Unlike {@link
*** 99,108 **** --- 100,114 ---- /** * The ERA constant designating the Heisei era. */ public static final int HEISEI = 4; + /** + * The ERA constant designating the NewEra era. + */ + private static final int NEWERA = 5; + private static final int EPOCH_OFFSET = 719163; // Fixed date of January 1, 1970 (Gregorian) private static final int EPOCH_YEAR = 1970; // Useful millisecond constants. Although ONE_DAY and ONE_WEEK can fit // into ints, they must be longs in order to prevent arithmetic overflow
*** 131,140 **** --- 137,149 ---- private static final Era[] eras; // Fixed date of the first date of each era. private static final long[] sinceFixedDates; + // The current era + private static final int currentEra; + /* * <pre> * Greatest Least * Field name Minimum Minimum Maximum Maximum * ---------- ------- ------- ------- -------
*** 226,242 **** --- 235,256 ---- sinceFixedDates = new long[length]; // eras[BEFORE_MEIJI] and sinceFixedDate[BEFORE_MEIJI] are the // same as Gregorian. int index = BEFORE_MEIJI; + int current = index; sinceFixedDates[index] = gcal.getFixedDate(BEFORE_MEIJI_ERA.getSinceDate()); eras[index++] = BEFORE_MEIJI_ERA; for (Era e : es) { + if(e.getSince(TimeZone.NO_TIMEZONE) < System.currentTimeMillis()) { + current = index; + } CalendarDate d = e.getSinceDate(); sinceFixedDates[index] = gcal.getFixedDate(d); eras[index++] = e; } + currentEra = current; LEAST_MAX_VALUES[ERA] = MAX_VALUES[ERA] = eras.length - 1; // Calculate the least maximum year and least day of Year // values. The following code assumes that there's at most one
*** 1711,1726 **** if (d.isLeapYear()) { --prevJan1; } } else if (transitionYear) { if (jdate.getYear() == 1) { ! // As of Heisei (since Meiji) there's no case // that there are multiple transitions in a // year. Historically there was such // case. There might be such case again in the // future. ! if (era > HEISEI) { CalendarDate pd = eras[era - 1].getSinceDate(); if (normalizedYear == pd.getYear()) { d.setMonth(pd.getMonth()).setDayOfMonth(pd.getDayOfMonth()); } } else { --- 1725,1740 ---- if (d.isLeapYear()) { --prevJan1; } } else if (transitionYear) { if (jdate.getYear() == 1) { ! // As of NewEra (since Meiji) there's no case // that there are multiple transitions in a // year. Historically there was such // case. There might be such case again in the // future. ! if (era > NEWERA) { CalendarDate pd = eras[era - 1].getSinceDate(); if (normalizedYear == pd.getYear()) { d.setMonth(pd.getMonth()).setDayOfMonth(pd.getDayOfMonth()); } } else {
*** 1851,1861 **** if (isSet(ERA)) { era = internalGet(ERA); year = isSet(YEAR) ? internalGet(YEAR) : 1; } else { if (isSet(YEAR)) { ! era = eras.length - 1; year = internalGet(YEAR); } else { // Equivalent to 1970 (Gregorian) era = SHOWA; year = 45; --- 1865,1875 ---- if (isSet(ERA)) { era = internalGet(ERA); year = isSet(YEAR) ? internalGet(YEAR) : 1; } else { if (isSet(YEAR)) { ! era = currentEra; year = internalGet(YEAR); } else { // Equivalent to 1970 (Gregorian) era = SHOWA; year = 45;
*** 2335,2345 **** /** * Returns the ERA. We need a special method for this because the * default ERA is the current era, but a zero (unset) ERA means before Meiji. */ private int internalGetEra() { ! return isSet(ERA) ? internalGet(ERA) : eras.length - 1; } /** * Updates internal state. */ --- 2349,2359 ---- /** * Returns the ERA. We need a special method for this because the * default ERA is the current era, but a zero (unset) ERA means before Meiji. */ private int internalGetEra() { ! return isSet(ERA) ? internalGet(ERA) : currentEra; } /** * Updates internal state. */
< prev index next >