< prev index next >

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

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * 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
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -48,10 +48,11 @@
  *     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,10 +100,15 @@
     /**
      * 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,10 +137,13 @@
     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,17 +235,22 @@
         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,16 +1725,16 @@
                     if (d.isLeapYear()) {
                         --prevJan1;
                     }
                 } 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());
                             }
                         } else {

@@ -1851,11 +1865,11 @@
         if (isSet(ERA)) {
             era = internalGet(ERA);
             year = isSet(YEAR) ? internalGet(YEAR) : 1;
         } else {
             if (isSet(YEAR)) {
-                era = eras.length - 1;
+                era = currentEra;
                 year = internalGet(YEAR);
             } else {
                 // Equivalent to 1970 (Gregorian)
                 era = SHOWA;
                 year = 45;

@@ -2335,11 +2349,11 @@
     /**
      * 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;
+        return isSet(ERA) ? internalGet(ERA) : currentEra;
     }
 
     /**
      * Updates internal state.
      */
< prev index next >