aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandroid-build-team Robot <android-build-team-robot@google.com>2019-05-14 19:53:32 +0000
committerandroid-build-team Robot <android-build-team-robot@google.com>2019-05-14 19:53:32 +0000
commit650d7f2e713b4c7fbbb4eb78157026592aa8f454 (patch)
tree9cc08443f1a9d67cc24296e00362772eba51d612
parent2b93f7f9da6dc2d4a82e9dcdf549d1c76873961a (diff)
parent9897d6ea112b4d490ef7b2b9463f41ed536f6754 (diff)
downloadlibcore-650d7f2e713b4c7fbbb4eb78157026592aa8f454.tar.gz
Merge cherrypicks of [7508933, 7508817, 7509318, 7508934, 7509262, 7509263, 7509264, 7508935, 7508630, 7508631, 7508632, 7508633, 7508634, 7509319, 7508937, 7508841, 7509320, 7508842] into pi-qpr3-releaseandroid-9.0.0_r46android-9.0.0_r44android-9.0.0_r43pie-qpr3-release
Change-Id: I504899ec83eb9c8b15ac9d896d68e81dd4f88b0a
-rw-r--r--luni/src/test/java/libcore/java/time/chrono/JapaneseChronologyTest.java13
-rw-r--r--ojluni/src/main/java/java/time/chrono/JapaneseEra.java93
-rw-r--r--ojluni/src/main/java/java/util/JapaneseImperialCalendar.java31
-rw-r--r--ojluni/src/main/java/sun/util/calendar/Era.java3
-rw-r--r--ojluni/src/main/resources/calendars.properties4
-rw-r--r--ojluni/src/test/java/time/tck/java/time/chrono/TCKJapaneseChronology.java50
-rw-r--r--ojluni/src/test/java/time/tck/java/time/chrono/TCKJapaneseEra.java13
-rw-r--r--ojluni/src/test/java/time/test/java/time/chrono/TestJapaneseChronology.java70
-rw-r--r--ojluni/src/test/java/time/test/java/time/chrono/TestUmmAlQuraChronology.java12
-rw-r--r--ojluni/src/test/java/time/test/java/time/format/TestNonIsoFormatter.java35
10 files changed, 283 insertions, 41 deletions
diff --git a/luni/src/test/java/libcore/java/time/chrono/JapaneseChronologyTest.java b/luni/src/test/java/libcore/java/time/chrono/JapaneseChronologyTest.java
index 3c1f0cf5617..1f36b2c6ed5 100644
--- a/luni/src/test/java/libcore/java/time/chrono/JapaneseChronologyTest.java
+++ b/luni/src/test/java/libcore/java/time/chrono/JapaneseChronologyTest.java
@@ -16,6 +16,8 @@
package libcore.java.time.chrono;
import org.junit.Test;
+import android.icu.util.JapaneseCalendar;
+import java.util.List;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalTime;
@@ -23,6 +25,7 @@ import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.chrono.ChronoZonedDateTime;
+import java.time.chrono.Era;
import java.time.chrono.JapaneseChronology;
import java.time.chrono.JapaneseDate;
import java.time.chrono.JapaneseEra;
@@ -110,4 +113,14 @@ public class JapaneseChronologyTest {
assertEquals(true, date.isSupported(ChronoField.YEAR));
assertEquals(true, date.isSupported(ChronoField.YEAR_OF_ERA));
}
+
+ @Test
+ public void test_eras_isLatestEraConsistency() {
+ List<Era> japaneseEras = JapaneseChronology.INSTANCE.eras();
+ boolean isHeiseiLatestInJavaTime =
+ japaneseEras.get(japaneseEras.size()-1).getValue() <= JapaneseEra.HEISEI.getValue();
+ boolean isHeiseiLatestInIcu = JapaneseCalendar.CURRENT_ERA == JapaneseCalendar.HEISEI;
+ assertEquals("java.time and ICU4J are not consistent in the latest japanese era",
+ isHeiseiLatestInJavaTime, isHeiseiLatestInIcu);
+ }
}
diff --git a/ojluni/src/main/java/java/time/chrono/JapaneseEra.java b/ojluni/src/main/java/java/time/chrono/JapaneseEra.java
index 0c9e3e81e1d..d52f3c19c98 100644
--- a/ojluni/src/main/java/java/time/chrono/JapaneseEra.java
+++ b/ojluni/src/main/java/java/time/chrono/JapaneseEra.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 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
@@ -73,11 +73,14 @@ import java.io.ObjectStreamException;
import java.io.Serializable;
import java.time.DateTimeException;
import java.time.LocalDate;
+import java.time.format.DateTimeFormatterBuilder;
+import java.time.format.TextStyle;
import java.time.temporal.ChronoField;
import java.time.temporal.TemporalField;
import java.time.temporal.UnsupportedTemporalTypeException;
import java.time.temporal.ValueRange;
import java.util.Arrays;
+import java.util.Locale;
import java.util.Objects;
import sun.util.calendar.CalendarDate;
@@ -85,10 +88,33 @@ import sun.util.calendar.CalendarDate;
/**
* An era in the Japanese Imperial calendar system.
* <p>
- * This class defines the valid eras for the Japanese chronology.
- * Japan introduced the Gregorian calendar starting with Meiji 6.
- * Only Meiji and later eras are supported;
- * dates before Meiji 6, January 1 are not supported.
+ * The Japanese government defines the official name and start date of
+ * each era. Eras are consecutive and their date ranges do not overlap,
+ * so the end date of one era is always the day before the start date
+ * of the next era.
+ * <p>
+ * The Java SE Platform supports all eras defined by the Japanese government,
+ * beginning with the Meiji era. Each era is identified in the Platform by an
+ * integer value and a name. The {@link #of(int)} and {@link #valueOf(String)}
+ * methods may be used to obtain a singleton instance of JapaneseEra for each
+ * era. The {@link #values()} method returns the singleton instances of all
+ * supported eras.
+ * <p>
+ * For convenience, this class declares a number of public static final fields
+ * that refer to singleton instances returned by the values() method.
+ *
+ * @apiNote
+ * The fields declared in this class may evolve over time, in line with the
+ * results of the {@link #values()} method. However, there is not necessarily
+ * a 1:1 correspondence between the fields and the singleton instances.
+ *
+ * @apiNote
+ * The Japanese government may announce a new era and define its start
+ * date but not its official name. In this scenario, the singleton instance
+ * that represents the new era may return a name that is not stable until
+ * the official name is defined. Developers should exercise caution when
+ * relying on the name returned by any singleton instance that does not
+ * correspond to a public static final field.
*
* @implSpec
* This class is immutable and thread-safe.
@@ -120,14 +146,20 @@ public final class JapaneseEra
*/
public static final JapaneseEra SHOWA = new JapaneseEra(1, LocalDate.of(1926, 12, 25));
/**
- * The singleton instance for the 'Heisei' era (1989-01-08 - current)
+ * The singleton instance for the 'Heisei' era (1989-01-08 - 2019-04-30)
* which has the value 2.
*/
public static final JapaneseEra HEISEI = new JapaneseEra(2, LocalDate.of(1989, 1, 8));
+ /**
+ * 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 REIWA = new JapaneseEra(3, LocalDate.of(2019, 5, 1));
- // the number of defined JapaneseEra constants.
- // There could be an extra era defined in its configuration.
- private static final int N_ERA_CONSTANTS = HEISEI.getValue() + ERA_OFFSET;
+ // The number of predefined JapaneseEra constants.
+ // There may be a supplemental era defined by the property.
+ private static final int N_ERA_CONSTANTS = REIWA.getValue() + ERA_OFFSET;
/**
* Serialization version.
@@ -145,6 +177,7 @@ public final class JapaneseEra
KNOWN_ERAS[1] = TAISHO;
KNOWN_ERAS[2] = SHOWA;
KNOWN_ERAS[3] = HEISEI;
+ 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());
@@ -185,10 +218,18 @@ public final class JapaneseEra
//-----------------------------------------------------------------------
/**
* Obtains an instance of {@code JapaneseEra} from an {@code int} value.
+ * <ul>
+ * <li>The value {@code 1} is associated with the 'Showa' era, because
+ * it contains 1970-01-01 (ISO calendar system).</li>
+ * <li>The values {@code -1} and {@code 0} are associated with two earlier
+ * eras, Meiji and Taisho, respectively.</li>
+ * <li>A value greater than {@code 1} is associated with a later era,
+ * beginning with Heisei ({@code 2}).</li>
+ * </ul>
* <p>
- * The {@link #SHOWA} era that contains 1970-01-01 (ISO calendar system) has the value 1
- * Later era is numbered 2 ({@link #HEISEI}). Earlier eras are numbered 0 ({@link #TAISHO}),
- * -1 ({@link #MEIJI}), only Meiji and later eras are supported.
+ * Every instance of {@code JapaneseEra} that is returned from the {@link #values()}
+ * method has an int value (available via {@link Era#getValue()} which is
+ * accepted by this method.
*
* @param japaneseEra the era to represent
* @return the {@code JapaneseEra} singleton, not null
@@ -236,6 +277,28 @@ public final class JapaneseEra
return Arrays.copyOf(KNOWN_ERAS, KNOWN_ERAS.length);
}
+ /**
+ * {@inheritDoc}
+ *
+ * @param style {@inheritDoc}
+ * @param locale {@inheritDoc}
+ */
+ @Override
+ public String getDisplayName(TextStyle style, Locale locale) {
+ // If this JapaneseEra is a supplemental one, obtain the name from
+ // the era definition.
+ if (getValue() > N_ERA_CONSTANTS - ERA_OFFSET) {
+ Objects.requireNonNull(locale, "locale");
+ return style.asNormal() == TextStyle.NARROW ? getAbbreviation() : getName();
+ }
+
+ return new DateTimeFormatterBuilder()
+ .appendText(ERA, style)
+ .toFormatter(locale)
+ .withChronology(JapaneseChronology.INSTANCE)
+ .format(this == MEIJI ? MEIJI_6_ISODATE : since);
+ }
+
//-----------------------------------------------------------------------
/**
* Obtains an instance of {@code JapaneseEra} from a date.
@@ -337,11 +400,7 @@ public final class JapaneseEra
//-----------------------------------------------------------------------
String getAbbreviation() {
- int index = ordinal(getValue());
- if (index == 0) {
- return "";
- }
- return ERA_CONFIG[index].getAbbreviation();
+ return ERA_CONFIG[ordinal(getValue())].getAbbreviation();
}
String getName() {
diff --git a/ojluni/src/main/java/java/util/JapaneseImperialCalendar.java b/ojluni/src/main/java/java/util/JapaneseImperialCalendar.java
index c5699810544..9bca22a57a3 100644
--- a/ojluni/src/main/java/java/util/JapaneseImperialCalendar.java
+++ b/ojluni/src/main/java/java/util/JapaneseImperialCalendar.java
@@ -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
@@ -49,6 +49,7 @@ import sun.util.calendar.LocalGregorianCalendar;
* 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 Reiwa 2019-05-01 midnight local time
* ------------------------------------------------------
* </tt></pre>
*
@@ -100,6 +101,11 @@ class JapaneseImperialCalendar extends Calendar {
*/
public static final int HEISEI = 4;
+ /**
+ * The ERA constant designating the Reiwa era.
+ */
+ 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;
@@ -132,6 +138,9 @@ class JapaneseImperialCalendar extends Calendar {
// 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
@@ -227,13 +236,25 @@ class JapaneseImperialCalendar extends Calendar {
// eras[BEFORE_MEIJI] and sinceFixedDate[BEFORE_MEIJI] are the
// same as Gregorian.
int index = BEFORE_MEIJI;
+ // Android-removed: Zygote could initialize this class when system has outdated time.
+ // int current = index;
sinceFixedDates[index] = gcal.getFixedDate(BEFORE_MEIJI_ERA.getSinceDate());
eras[index++] = BEFORE_MEIJI_ERA;
for (Era e : es) {
+ // Android-removed: Zygote could initialize this class when system has outdated time.
+ // Android hard-code the current era. Unlike upstream, Android does not add the new era
+ // in the code until the new era arrives. Thus, Android can't have newer era than the
+ // real world. currentEra is the latest Era that Android knows about.
+ // if(e.getSince(TimeZone.NO_TIMEZONE) < System.currentTimeMillis()) {
+ // current = index;
+ // }
CalendarDate d = e.getSinceDate();
sinceFixedDates[index] = gcal.getFixedDate(d);
eras[index++] = e;
}
+ // Android-changed: Zygote could initialize this class when system has outdated time.
+ // currentEra = current;
+ currentEra = REIWA;
LEAST_MAX_VALUES[ERA] = MAX_VALUES[ERA] = eras.length - 1;
@@ -1713,12 +1734,12 @@ class JapaneseImperialCalendar extends Calendar {
}
} else if (transitionYear) {
if (jdate.getYear() == 1) {
- // As of Heisei (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 > HEISEI) {
+ if (era > REIWA) {
CalendarDate pd = eras[era - 1].getSinceDate();
if (normalizedYear == pd.getYear()) {
d.setMonth(pd.getMonth()).setDayOfMonth(pd.getDayOfMonth());
@@ -1853,7 +1874,7 @@ class JapaneseImperialCalendar extends Calendar {
year = isSet(YEAR) ? internalGet(YEAR) : 1;
} else {
if (isSet(YEAR)) {
- era = eras.length - 1;
+ era = currentEra;
year = internalGet(YEAR);
} else {
// Equivalent to 1970 (Gregorian)
@@ -2338,7 +2359,7 @@ class JapaneseImperialCalendar extends Calendar {
* 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;
}
/**
diff --git a/ojluni/src/main/java/sun/util/calendar/Era.java b/ojluni/src/main/java/sun/util/calendar/Era.java
index a013c57afd2..7c02cce73e2 100644
--- a/ojluni/src/main/java/sun/util/calendar/Era.java
+++ b/ojluni/src/main/java/sun/util/calendar/Era.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 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
@@ -49,6 +49,7 @@ import java.util.TimeZone;
* Taisho 1912-07-30 midnight local time
* Showa 1926-12-26 midnight local time
* Heisei 1989-01-08 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/main/resources/calendars.properties b/ojluni/src/main/resources/calendars.properties
index 49f68aca492..6007d7a57df 100644
--- a/ojluni/src/main/resources/calendars.properties
+++ b/ojluni/src/main/resources/calendars.properties
@@ -29,12 +29,14 @@
# Taisho since 1912-07-30 00:00:00 local time (Gregorian)
# Showa since 1926-12-25 00:00:00 local time (Gregorian)
# Heisei since 1989-01-08 00:00:00 local time (Gregorian)
+# Reiwa since 2019-05-01 00:00:00 local time (Gregorian)
calendar.japanese.type: LocalGregorianCalendar
calendar.japanese.eras: \
name=Meiji,abbr=M,since=-3218832000000; \
name=Taisho,abbr=T,since=-1812153600000; \
name=Showa,abbr=S,since=-1357603200000; \
- name=Heisei,abbr=H,since=600220800000
+ name=Heisei,abbr=H,since=600220800000; \
+ name=Reiwa,abbr=R,since=1556668800000
#
# Taiwanese calendar
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 2bc1f4c8ce7..394d6d58e76 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
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 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
@@ -111,6 +111,24 @@ import org.testng.annotations.Test;
*/
@Test
public class TCKJapaneseChronology {
+
+ // Android-added: Add a static field to indicate if the device supports the new Japanese era.
+ /**
+ * Indicates if the device support newer Japenese Era than Heisei. Old Android releases can
+ * optionally support new Japanese Era, e.g. Reiwa, and Android test suites, e.g. CTS, can use
+ * this flag to alter the expected result. This flag can be placed in other classes, but
+ * TCKJapaneseChronology is picked arbitrarily.
+ */
+ public static final boolean IS_HEISEI_LATEST;
+ static {
+ List<Era> japaneseEras = JapaneseChronology.INSTANCE.eras();
+ IS_HEISEI_LATEST =
+ japaneseEras.get(japaneseEras.size()-1).getValue() <= JapaneseEra.HEISEI.getValue();
+ }
+
+
+ // 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;
@@ -173,6 +191,10 @@ public class TCKJapaneseChronology {
@DataProvider(name="createByEra")
Object[][] data_createByEra() {
return new Object[][] {
+ // Android-changed: Old Android releases can optionally support the new Japanese era.
+ IS_HEISEI_LATEST
+ ? new Object[] {JapaneseEra.HEISEI, 2020 - YDIFF_HEISEI, 2, 29, 60, LocalDate.of(2020, 2, 29)}
+ : new Object[] {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)},
@@ -365,8 +387,16 @@ public class TCKJapaneseChronology {
@DataProvider(name="prolepticYear")
Object[][] data_prolepticYear() {
return new Object[][] {
+ // Android-changed: Old Android releases can optionally support the new Japanese era.
+ IS_HEISEI_LATEST
+ ? new Object[] {2, JapaneseEra.HEISEI, 1, 1 + YDIFF_HEISEI, false}
+ : new Object[] {3, JapaneseEra.of(3), 1, 1 + YDIFF_REIWA, false},
+ IS_HEISEI_LATEST
+ ? new Object[] {2, JapaneseEra.HEISEI, 102, 102 + YDIFF_HEISEI, false}
+ : new Object[] {3, JapaneseEra.of(3), 102, 102 + YDIFF_REIWA, true},
+
{2, JapaneseEra.HEISEI, 1, 1 + YDIFF_HEISEI, false},
- {2, JapaneseEra.HEISEI, 100, 100 + YDIFF_HEISEI, true},
+ {2, JapaneseEra.HEISEI, 4, 4 + YDIFF_HEISEI, true},
{-1, JapaneseEra.MEIJI, 9, 9 + YDIFF_MEIJI, true},
{-1, JapaneseEra.MEIJI, 10, 10 + YDIFF_MEIJI, false},
@@ -543,6 +573,16 @@ public class TCKJapaneseChronology {
//-----------------------------------------------------------------------
@DataProvider(name="japaneseEras")
Object[][] data_japanseseEras() {
+ // Android-changed: Old Android releases can optionally support the new Japanese era.
+ if (!IS_HEISEI_LATEST) {
+ return new Object[][] {
+ { JapaneseEra.MEIJI, -1, "Meiji"},
+ { JapaneseEra.TAISHO, 0, "Taisho"},
+ { JapaneseEra.SHOWA, 1, "Showa"},
+ { JapaneseEra.HEISEI, 2, "Heisei"},
+ { JapaneseEra.of(3), 3, "Reiwa"},
+ };
+ }
return new Object[][] {
{ JapaneseEra.MEIJI, -1, "Meiji"},
{ JapaneseEra.TAISHO, 0, "Taisho"},
@@ -562,7 +602,7 @@ public class TCKJapaneseChronology {
@Test
public void test_Japanese_badEras() {
- int badEras[] = {-1000, -998, -997, -2, 3, 4, 1000};
+ int badEras[] = {-1000, -998, -997, -2, 4, 5, 1000};
for (int badEra : badEras) {
try {
Era era = JapaneseChronology.INSTANCE.eraOf(badEra);
@@ -683,6 +723,10 @@ public class TCKJapaneseChronology {
{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"},
+ // Android-changed: Old Android releases can optionally support the new Japanese era.
+ IS_HEISEI_LATEST
+ ? new Object[] {JapaneseChronology.INSTANCE.date(2020, 1, 6), "Japanese Heisei 32-01-06"}
+ : new Object[] {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 de83e1d3bc3..815517c8152 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
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 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
@@ -59,6 +59,7 @@ package tck.java.time.chrono;
import static java.time.temporal.ChronoField.ERA;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
+import static tck.java.time.chrono.TCKJapaneseChronology.IS_HEISEI_LATEST;
import java.time.chrono.Era;
import java.time.chrono.JapaneseChronology;
@@ -76,6 +77,16 @@ public class TCKJapaneseEra {
@DataProvider(name = "JapaneseEras")
Object[][] data_of_eras() {
+ // Android-changed: Old Android releases can optionally support the new Japanese era.
+ if (!IS_HEISEI_LATEST) {
+ return new Object[][] {
+ {JapaneseEra.of(3), "Reiwa", 3},
+ {JapaneseEra.HEISEI, "Heisei", 2},
+ {JapaneseEra.SHOWA, "Showa", 1},
+ {JapaneseEra.TAISHO, "Taisho", 0},
+ {JapaneseEra.MEIJI, "Meiji", -1},
+ };
+ }
return new Object[][] {
{JapaneseEra.HEISEI, "Heisei", 2},
{JapaneseEra.SHOWA, "Showa", 1},
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 3fbf8532318..337a8dbc3d7 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
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 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
@@ -28,12 +28,15 @@ package test.java.time.chrono;
import java.time.*;
import java.time.chrono.*;
import java.time.temporal.*;
+import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+import static tck.java.time.chrono.TCKJapaneseChronology.IS_HEISEI_LATEST;
/**
* Tests for the Japanese chronology
@@ -45,7 +48,8 @@ public class TestJapaneseChronology {
@DataProvider(name="transitions")
Object[][] transitionData() {
- return new Object[][] {
+ // Android-changed: Old Android releases can optionally support the new Japanese era.
+ List<Object[]> data = Arrays.asList(new Object[][] {
// Japanese era, yearOfEra, month, dayOfMonth, gregorianYear
{ JapaneseEra.MEIJI, 6, 1, 1, 1873 },
// Meiji-Taisho transition isn't accurate. 1912-07-30 is the last day of Meiji
@@ -58,12 +62,20 @@ public class TestJapaneseChronology {
{ JapaneseEra.SHOWA, 1, 12, 25, 1926 },
{ JapaneseEra.SHOWA, 64, 1, 7, 1989 },
{ JapaneseEra.HEISEI, 1, 1, 8, 1989 },
- };
+ });
+ if (IS_HEISEI_LATEST) {
+ data.addAll(Arrays.asList(new Object[][] {
+ { JapaneseEra.HEISEI, 31, 4, 30, 2019 },
+ { JapaneseEra.of(3), 1, 5, 1, 2019 },
+ }));
+ }
+ return data.toArray(new Object[data.size()][]);
}
@DataProvider(name="day_year_data")
Object[][] dayYearData() {
- return new Object[][] {
+ // Android-changed: Old Android releases can optionally support the new Japanese era.
+ List<Object[]> data = Arrays.asList(new Object[][] {
// Japanese era, yearOfEra, dayOfYear, month, dayOfMonth
{ JapaneseEra.MEIJI, 45, 211, 7, 29 },
{ JapaneseEra.TAISHO, 1, 1, 7, 30 },
@@ -74,15 +86,25 @@ public class TestJapaneseChronology {
{ JapaneseEra.SHOWA, 64, 7, 1, 7 },
{ JapaneseEra.HEISEI, 1, 1, 1, 8 },
{ JapaneseEra.HEISEI, 2, 8, 1, 8 },
- };
+ });
+ if (IS_HEISEI_LATEST) {
+ data.addAll(Arrays.asList(new Object[][] {
+ { JapaneseEra.HEISEI, 31, 120, 4, 30 },
+ { JapaneseEra.of(3), 1, 1, 5, 1 },
+ }));
+ }
+ return data.toArray(new Object[data.size()][]);
}
@DataProvider(name="range_data")
Object[][] rangeData() {
+ // Android-changed: Old Android releases can optionally support the new Japanese era.
+ int maxEra = IS_HEISEI_LATEST ? 2 : 3;
+ int yearOfLatestEra = IS_HEISEI_LATEST ? 1989 : 2019;
return new Object[][] {
// field, minSmallest, minLargest, maxSmallest, maxLargest
- { ChronoField.ERA, -1, -1, 2, 2},
- { ChronoField.YEAR_OF_ERA, 1, 1, 15, 999999999-1989 }, // depends on the current era
+ { ChronoField.ERA, -1, -1, maxEra, maxEra},
+ { ChronoField.YEAR_OF_ERA, 1, 1, 15, 999999999-yearOfLatestEra}, // depends on the current era
{ ChronoField.DAY_OF_YEAR, 1, 1, 7, 366},
{ ChronoField.YEAR, 1873, 1873, 999999999, 999999999},
};
@@ -105,7 +127,9 @@ public class TestJapaneseChronology {
{ JapaneseEra.SHOWA, 65, 1, 1 },
{ JapaneseEra.HEISEI, 1, 1, 7 },
{ JapaneseEra.HEISEI, 1, 2, 29 },
- { JapaneseEra.HEISEI, Year.MAX_VALUE, 12, 31 },
+ { JapaneseEra.HEISEI, 31, 5, 1 },
+ { JapaneseEra.of(3), 1, 4, 30 },
+ { JapaneseEra.of(3), Year.MAX_VALUE, 12, 31 },
};
}
@@ -124,7 +148,10 @@ public class TestJapaneseChronology {
{ JapaneseEra.SHOWA, 65 },
{ JapaneseEra.HEISEI, -1 },
{ JapaneseEra.HEISEI, 0 },
- { JapaneseEra.HEISEI, Year.MAX_VALUE },
+ { JapaneseEra.HEISEI, 32 },
+ { JapaneseEra.of(3), -1 },
+ { JapaneseEra.of(3), 0 },
+ { JapaneseEra.of(3), Year.MAX_VALUE },
};
}
@@ -141,6 +168,22 @@ public class TestJapaneseChronology {
{ JapaneseEra.SHOWA, 64, 8 },
{ JapaneseEra.HEISEI, 1, 360 },
{ JapaneseEra.HEISEI, 2, 366 },
+ { JapaneseEra.HEISEI, 31, 121 },
+ { 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},
};
}
@@ -192,4 +235,13 @@ public class TestJapaneseChronology {
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 ab61c71e696..e2f2b7740c8 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
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 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
@@ -33,6 +33,7 @@ import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
+import static tck.java.time.chrono.TCKJapaneseChronology.IS_HEISEI_LATEST;
import java.time.DateTimeException;
import java.time.DayOfWeek;
@@ -72,6 +73,7 @@ import org.testng.annotations.Test;
/**
* Tests for the Umm alQura chronology and data.
* Note: The dates used for testing are just a sample of calendar data.
+ * @bug 8067800
*/
@Test
public class TestUmmAlQuraChronology {
@@ -548,6 +550,7 @@ public class TestUmmAlQuraChronology {
assertFalse(HijrahChronology.INSTANCE.isLeapYear(y), "Out of range leap year");
}
+
// Date samples to convert HijrahDate to LocalDate and vice versa
@DataProvider(name="samples")
Object[][] data_samples() {
@@ -773,8 +776,11 @@ public class TestUmmAlQuraChronology {
{HijrahDate.of(1350,5,15), "Japanese Showa 6-09-28"},
{HijrahDate.of(1434,5,1), "Japanese Heisei 25-03-13"},
{HijrahDate.of(1436,1,1), "Japanese Heisei 26-10-25"},
- {HijrahDate.of(1500,6,12), "Japanese Heisei 89-05-05"},
- {HijrahDate.of(1550,3,11), "Japanese Heisei 137-08-11"},
+ {HijrahDate.of(1440,8,25), "Japanese Heisei 31-04-30"},
+ // Android-changed: Old Android releases can optionally support the new Japanese era.
+ {HijrahDate.of(1440,8,26), IS_HEISEI_LATEST ? "Japanese Heisei 31-05-01" : "Japanese Reiwa 1-05-01"},
+ {HijrahDate.of(1500,6,12), IS_HEISEI_LATEST ? "Japanese Heisei 89-05-05" : "Japanese Reiwa 59-05-05"},
+ {HijrahDate.of(1550,3,11), IS_HEISEI_LATEST ? "Japanese Heisei 137-08-11" : "Japanese Reiwa 107-08-11"},
};
}
diff --git a/ojluni/src/test/java/time/test/java/time/format/TestNonIsoFormatter.java b/ojluni/src/test/java/time/test/java/time/format/TestNonIsoFormatter.java
index 1edaba6f903..e53adad2c90 100644
--- a/ojluni/src/test/java/time/test/java/time/format/TestNonIsoFormatter.java
+++ b/ojluni/src/test/java/time/test/java/time/format/TestNonIsoFormatter.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 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
@@ -20,9 +20,17 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
+
+/*
+ *
+ * @test
+ * @bug 8206120
+ */
+
package test.java.time.format;
import static org.testng.Assert.assertEquals;
+import static tck.java.time.chrono.TCKJapaneseChronology.IS_HEISEI_LATEST;
import java.time.LocalDate;
import java.time.chrono.ChronoLocalDate;
@@ -37,6 +45,7 @@ import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.time.format.DateTimeParseException;
import java.time.format.FormatStyle;
+import java.time.format.ResolverStyle;
import java.time.format.TextStyle;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalQueries;
@@ -134,6 +143,19 @@ public class TestNonIsoFormatter {
};
}
+ @DataProvider(name="lenient_eraYear")
+ Object[][] lenientEraYear() {
+ return new Object[][] {
+ // Chronology, lenient era/year, strict era/year
+ { JAPANESE, "Meiji 123", "Heisei 2" },
+ // Android-changed: Eras names have been changed in CLDR data.
+ // { JAPANESE, "Showa 65", "Heisei 2" }
+ { JAPANESE, "Shōwa 65", "Heisei 2" },
+ // Android-changed: Old Android releases can optionally support the new Japanese era.
+ { JAPANESE, "Heisei 32", IS_HEISEI_LATEST ? "Heisei 32" : "Reiwa 2" },
+ };
+ }
+
@Test(dataProvider="format_data")
public void test_formatLocalizedDate(Chronology chrono, Locale formatLocale, Locale numberingLocale,
ChronoLocalDate date, String expected) {
@@ -172,4 +194,15 @@ public class TestNonIsoFormatter {
Chronology cal = ta.query(TemporalQueries.chronology());
assertEquals(cal, chrono);
}
+
+ @Test(dataProvider="lenient_eraYear")
+ public void test_lenientEraYear(Chronology chrono, String lenient, String strict) {
+ String mdStr = "-01-01";
+ DateTimeFormatter dtf = new DateTimeFormatterBuilder()
+ .appendPattern("GGGG y-M-d")
+ .toFormatter()
+ .withChronology(chrono);
+ DateTimeFormatter dtfLenient = dtf.withResolverStyle(ResolverStyle.LENIENT);
+ assertEquals(LocalDate.parse(lenient+mdStr, dtfLenient), LocalDate.parse(strict+mdStr, dtf));
+ }
}