--- old/src/share/classes/java/util/JapaneseImperialCalendar.java 2019-02-19 15:24:53.542619000 +0530 +++ new/src/share/classes/java/util/JapaneseImperialCalendar.java 2019-02-19 15:24:52.417692900 +0530 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. + * 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 @@ -50,6 +50,7 @@ * 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 * ------------------------------------------------------ * * @@ -101,6 +102,11 @@ */ 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; @@ -133,6 +139,9 @@ // Fixed date of the first date of each era. private static final long[] sinceFixedDates; + // The current era + private static final int currentEra; + /* *
* Greatest Least @@ -228,13 +237,18 @@ // 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; @@ -1713,12 +1727,12 @@ } } else if (transitionYear) { if (jdate.getYear() == 1) { - // As of Heisei (since Meiji) there's no case + // 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 > HEISEI) { + if (era > NEWERA) { CalendarDate pd = eras[era - 1].getSinceDate(); if (normalizedYear == pd.getYear()) { d.setMonth(pd.getMonth()).setDayOfMonth(pd.getDayOfMonth()); @@ -1853,7 +1867,7 @@ year = isSet(YEAR) ? internalGet(YEAR) : 1; } else { if (isSet(YEAR)) { - era = eras.length - 1; + era = currentEra; year = internalGet(YEAR); } else { // Equivalent to 1970 (Gregorian) @@ -2337,7 +2351,7 @@ * 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; + return isSet(ERA) ? internalGet(ERA) : currentEra; } /**