New Japanese Era implementation with actual Reiwa name
am: 87818a65fd
Change-Id: Idd1338d0010061d14f71eeec308f7e0b22a178d9
diff --git a/ojluni/src/main/java/java/time/chrono/JapaneseEra.java b/ojluni/src/main/java/java/time/chrono/JapaneseEra.java
index fd7aae7..d52f3c1 100644
--- a/ojluni/src/main/java/java/time/chrono/JapaneseEra.java
+++ b/ojluni/src/main/java/java/time/chrono/JapaneseEra.java
@@ -151,14 +151,15 @@
*/
public static final JapaneseEra HEISEI = new JapaneseEra(2, LocalDate.of(1989, 1, 8));
/**
- * The singleton instance for the 'NewEra' era (2019-05-01 - current)
- * which has the value 3.
+ * The singleton instance for the 'Reiwa' era (2019-05-01 - current)
+ * which has the value 3. The end date of this era is not specified, unless
+ * the Japanese Government defines it.
*/
- private static final JapaneseEra NEWERA = new JapaneseEra(3, LocalDate.of(2019, 5, 1));
+ private static final JapaneseEra REIWA = new JapaneseEra(3, LocalDate.of(2019, 5, 1));
// The number of predefined JapaneseEra constants.
// There may be a supplemental era defined by the property.
- private static final int N_ERA_CONSTANTS = NEWERA.getValue() + ERA_OFFSET;
+ private static final int N_ERA_CONSTANTS = REIWA.getValue() + ERA_OFFSET;
/**
* Serialization version.
@@ -176,7 +177,7 @@
KNOWN_ERAS[1] = TAISHO;
KNOWN_ERAS[2] = SHOWA;
KNOWN_ERAS[3] = HEISEI;
- KNOWN_ERAS[4] = NEWERA;
+ KNOWN_ERAS[4] = REIWA;
for (int i = N_ERA_CONSTANTS; i < ERA_CONFIG.length; i++) {
CalendarDate date = ERA_CONFIG[i].getSinceDate();
LocalDate isoDate = LocalDate.of(date.getYear(), date.getMonth(), date.getDayOfMonth());
diff --git a/ojluni/src/main/java/java/util/JapaneseImperialCalendar.java b/ojluni/src/main/java/java/util/JapaneseImperialCalendar.java
index 9d7a3e2..a0ee15e 100644
--- a/ojluni/src/main/java/java/util/JapaneseImperialCalendar.java
+++ b/ojluni/src/main/java/java/util/JapaneseImperialCalendar.java
@@ -49,7 +49,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
+ * 5 Reiwa 2019-05-01 midnight local time
* ------------------------------------------------------
* </tt></pre>
*
@@ -102,9 +102,9 @@
public static final int HEISEI = 4;
/**
- * The ERA constant designating the NewEra era.
+ * The ERA constant designating the Reiwa era.
*/
- private static final int NEWERA = 5;
+ private static final int REIWA = 5;
private static final int EPOCH_OFFSET = 719163; // Fixed date of January 1, 1970 (Gregorian)
private static final int EPOCH_YEAR = 1970;
@@ -254,7 +254,7 @@
}
// Android-changed: Zygote could initialize this class when system has outdated time.
// currentEra = current;
- currentEra = NEWERA;
+ currentEra = REIWA;
LEAST_MAX_VALUES[ERA] = MAX_VALUES[ERA] = eras.length - 1;
@@ -1737,12 +1737,12 @@
}
} else if (transitionYear) {
if (jdate.getYear() == 1) {
- // As of NewEra (since Meiji) there's no case
+ // As of Reiwa (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) {
+ if (era > REIWA) {
CalendarDate pd = eras[era - 1].getSinceDate();
if (normalizedYear == pd.getYear()) {
d.setMonth(pd.getMonth()).setDayOfMonth(pd.getDayOfMonth());
diff --git a/ojluni/src/main/java/sun/util/calendar/Era.java b/ojluni/src/main/java/sun/util/calendar/Era.java
index dea9cb4..7c02cce 100644
--- a/ojluni/src/main/java/sun/util/calendar/Era.java
+++ b/ojluni/src/main/java/sun/util/calendar/Era.java
@@ -49,7 +49,7 @@
* Taisho 1912-07-30 midnight local time
* Showa 1926-12-26 midnight local time
* Heisei 1989-01-08 midnight local time
- * NewEra 2019-05-01 midnight local time
+ * Reiwa 2019-05-01 midnight local time
* Julian calendar BeforeCommonEra -292275055-05-16T16:47:04.192Z
* CommonEra 0000-12-30 midnight local time
* Taiwanese calendar MinGuo 1911-01-01 midnight local time
diff --git a/ojluni/src/test/java/time/tck/java/time/chrono/TCKJapaneseChronology.java b/ojluni/src/test/java/time/tck/java/time/chrono/TCKJapaneseChronology.java
index 29714b3..091b385 100644
--- a/ojluni/src/test/java/time/tck/java/time/chrono/TCKJapaneseChronology.java
+++ b/ojluni/src/test/java/time/tck/java/time/chrono/TCKJapaneseChronology.java
@@ -111,7 +111,9 @@
*/
@Test
public class TCKJapaneseChronology {
- private static final int YDIFF_NEWERA = 2018;
+
+ // Year differences from Gregorian years.
+ private static final int YDIFF_REIWA = 2018;
private static final int YDIFF_HEISEI = 1988;
private static final int YDIFF_MEIJI = 1867;
private static final int YDIFF_SHOWA = 1925;
@@ -174,7 +176,7 @@
@DataProvider(name="createByEra")
Object[][] data_createByEra() {
return new Object[][] {
- {JapaneseEra.of(3), 2020 - YDIFF_NEWERA, 2, 29, 60, LocalDate.of(2020, 2, 29)}, // NEWERA
+ {JapaneseEra.of(3), 2020 - YDIFF_REIWA, 2, 29, 60, LocalDate.of(2020, 2, 29)}, // NEWERA
{JapaneseEra.HEISEI, 1996 - YDIFF_HEISEI, 2, 29, 60, LocalDate.of(1996, 2, 29)},
{JapaneseEra.HEISEI, 2000 - YDIFF_HEISEI, 2, 29, 60, LocalDate.of(2000, 2, 29)},
{JapaneseEra.MEIJI, 1874 - YDIFF_MEIJI, 2, 28, 59, LocalDate.of(1874, 2, 28)},
@@ -367,8 +369,8 @@
@DataProvider(name="prolepticYear")
Object[][] data_prolepticYear() {
return new Object[][] {
- {3, JapaneseEra.of(3), 1, 1 + YDIFF_NEWERA, false}, // NEWERA
- {3, JapaneseEra.of(3), 102, 102 + YDIFF_NEWERA, true}, // NEWERA
+ {3, JapaneseEra.of(3), 1, 1 + YDIFF_REIWA, false},
+ {3, JapaneseEra.of(3), 102, 102 + YDIFF_REIWA, true},
{2, JapaneseEra.HEISEI, 1, 1 + YDIFF_HEISEI, false},
{2, JapaneseEra.HEISEI, 4, 4 + YDIFF_HEISEI, true},
@@ -553,7 +555,7 @@
{ JapaneseEra.TAISHO, 0, "Taisho"},
{ JapaneseEra.SHOWA, 1, "Showa"},
{ JapaneseEra.HEISEI, 2, "Heisei"},
- { JapaneseEra.of(3), 3, "NewEra"}, // NEWERA
+ { JapaneseEra.of(3), 3, "Reiwa"},
};
}
@@ -689,7 +691,7 @@
{JapaneseChronology.INSTANCE.date(1989, 1, 7), "Japanese Showa 64-01-07"},
{JapaneseChronology.INSTANCE.date(1989, 1, 8), "Japanese Heisei 1-01-08"},
{JapaneseChronology.INSTANCE.date(2012, 12, 6), "Japanese Heisei 24-12-06"},
- {JapaneseChronology.INSTANCE.date(2020, 1, 6), "Japanese NewEra 2-01-06"},
+ {JapaneseChronology.INSTANCE.date(2020, 1, 6), "Japanese Reiwa 2-01-06"},
};
}
diff --git a/ojluni/src/test/java/time/tck/java/time/chrono/TCKJapaneseEra.java b/ojluni/src/test/java/time/tck/java/time/chrono/TCKJapaneseEra.java
index 943520d..e37a6a5 100644
--- a/ojluni/src/test/java/time/tck/java/time/chrono/TCKJapaneseEra.java
+++ b/ojluni/src/test/java/time/tck/java/time/chrono/TCKJapaneseEra.java
@@ -77,7 +77,7 @@
@DataProvider(name = "JapaneseEras")
Object[][] data_of_eras() {
return new Object[][] {
- {JapaneseEra.of(3), "NewEra", 3}, // NEWERA
+ {JapaneseEra.of(3), "Reiwa", 3},
{JapaneseEra.HEISEI, "Heisei", 2},
{JapaneseEra.SHOWA, "Showa", 1},
{JapaneseEra.TAISHO, "Taisho", 0},
diff --git a/ojluni/src/test/java/time/test/java/time/chrono/TestJapaneseChronology.java b/ojluni/src/test/java/time/test/java/time/chrono/TestJapaneseChronology.java
index a1df28a..03443d9 100644
--- a/ojluni/src/test/java/time/test/java/time/chrono/TestJapaneseChronology.java
+++ b/ojluni/src/test/java/time/test/java/time/chrono/TestJapaneseChronology.java
@@ -34,6 +34,7 @@
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
/**
* Tests for the Japanese chronology
@@ -59,7 +60,7 @@
{ JapaneseEra.SHOWA, 64, 1, 7, 1989 },
{ JapaneseEra.HEISEI, 1, 1, 8, 1989 },
{ JapaneseEra.HEISEI, 31, 4, 30, 2019 },
- { JapaneseEra.of(3), 1, 5, 1, 2019 }, // NEWERA
+ { JapaneseEra.of(3), 1, 5, 1, 2019 },
};
}
@@ -77,7 +78,7 @@
{ JapaneseEra.HEISEI, 1, 1, 1, 8 },
{ JapaneseEra.HEISEI, 2, 8, 1, 8 },
{ JapaneseEra.HEISEI, 31, 120, 4, 30 },
- { JapaneseEra.of(3), 1, 1, 5, 1 }, // NEWERA
+ { JapaneseEra.of(3), 1, 1, 5, 1 },
};
}
@@ -110,8 +111,8 @@
{ JapaneseEra.HEISEI, 1, 1, 7 },
{ JapaneseEra.HEISEI, 1, 2, 29 },
{ JapaneseEra.HEISEI, 31, 5, 1 },
- { JapaneseEra.of(3), 1, 4, 30 }, // NEWERA
- { JapaneseEra.of(3), Year.MAX_VALUE, 12, 31 }, // NEWERA
+ { JapaneseEra.of(3), 1, 4, 30 },
+ { JapaneseEra.of(3), Year.MAX_VALUE, 12, 31 },
};
}
@@ -131,9 +132,9 @@
{ JapaneseEra.HEISEI, -1 },
{ JapaneseEra.HEISEI, 0 },
{ JapaneseEra.HEISEI, 32 },
- { JapaneseEra.of(3), -1 }, // NEWERA
- { JapaneseEra.of(3), 0 }, // NEWERA
- { JapaneseEra.of(3), Year.MAX_VALUE }, // NEWERA
+ { JapaneseEra.of(3), -1 },
+ { JapaneseEra.of(3), 0 },
+ { JapaneseEra.of(3), Year.MAX_VALUE },
};
}
@@ -151,8 +152,21 @@
{ JapaneseEra.HEISEI, 1, 360 },
{ JapaneseEra.HEISEI, 2, 366 },
{ JapaneseEra.HEISEI, 31, 121 },
- { JapaneseEra.of(3), 1, 246 }, // NEWERA
- { JapaneseEra.of(3), 2, 367 }, // NEWERA
+ { JapaneseEra.of(3), 1, 246 },
+ { JapaneseEra.of(3), 2, 367 },
+ };
+ }
+
+ @DataProvider
+ Object[][] eraNameData() {
+ return new Object[][] {
+ // Japanese era, name, exception
+ { "Meiji", JapaneseEra.MEIJI, null },
+ { "Taisho", JapaneseEra.TAISHO, null },
+ { "Showa", JapaneseEra.SHOWA, null },
+ { "Heisei", JapaneseEra.HEISEI, null },
+ { "Reiwa", JapaneseEra.of(3), null },
+ { "NewEra", null, IllegalArgumentException.class},
};
}
@@ -204,4 +218,13 @@
JapaneseDate date = JAPANESE.dateYearDay(era, yearOfEra, dayOfYear);
System.out.printf("No DateTimeException with era=%s, year=%d, dayOfYear=%d%n", era, yearOfEra, dayOfYear);
}
+
+ @Test(dataProvider="eraNameData")
+ public void test_eraName(String eraName, JapaneseEra era, Class expectedEx) {
+ try {
+ assertEquals(JapaneseEra.valueOf(eraName), era);
+ } catch (Exception ex) {
+ assertTrue(expectedEx.isInstance(ex));
+ }
+ }
}
diff --git a/ojluni/src/test/java/time/test/java/time/chrono/TestUmmAlQuraChronology.java b/ojluni/src/test/java/time/test/java/time/chrono/TestUmmAlQuraChronology.java
index cb987f6..f86f144 100644
--- a/ojluni/src/test/java/time/test/java/time/chrono/TestUmmAlQuraChronology.java
+++ b/ojluni/src/test/java/time/test/java/time/chrono/TestUmmAlQuraChronology.java
@@ -776,9 +776,9 @@
{HijrahDate.of(1434,5,1), "Japanese Heisei 25-03-13"},
{HijrahDate.of(1436,1,1), "Japanese Heisei 26-10-25"},
{HijrahDate.of(1440,8,25), "Japanese Heisei 31-04-30"},
- {HijrahDate.of(1440,8,26), "Japanese NewEra 1-05-01"},
- {HijrahDate.of(1500,6,12), "Japanese NewEra 59-05-05"},
- {HijrahDate.of(1550,3,11), "Japanese NewEra 107-08-11"},
+ {HijrahDate.of(1440,8,26), "Japanese Reiwa 1-05-01"},
+ {HijrahDate.of(1500,6,12), "Japanese Reiwa 59-05-05"},
+ {HijrahDate.of(1550,3,11), "Japanese Reiwa 107-08-11"},
};
}