Snap for 5742267 from 7ef3464ff9b06a847e4df1e507defce1d72ae454 to pie-cts-release

Change-Id: Ia75a02d438e5f4387835b8229d3b89acd846da6e
diff --git a/android_icu4j/src/main/tests/android/icu/dev/data/testdata/format.res b/android_icu4j/src/main/tests/android/icu/dev/data/testdata/format.res
index 61e45b8..b6e62c2 100644
--- a/android_icu4j/src/main/tests/android/icu/dev/data/testdata/format.res
+++ b/android_icu4j/src/main/tests/android/icu/dev/data/testdata/format.res
Binary files differ
diff --git a/android_icu4j/src/main/tests/android/icu/dev/data/testdata/structLocale.res b/android_icu4j/src/main/tests/android/icu/dev/data/testdata/structLocale.res
index a1cb784..4a6b1e8 100644
--- a/android_icu4j/src/main/tests/android/icu/dev/data/testdata/structLocale.res
+++ b/android_icu4j/src/main/tests/android/icu/dev/data/testdata/structLocale.res
Binary files differ
diff --git a/android_icu4j/src/main/tests/android/icu/dev/test/calendar/JapaneseTest.java b/android_icu4j/src/main/tests/android/icu/dev/test/calendar/JapaneseTest.java
index 7ada8bb..03c8e6b 100644
--- a/android_icu4j/src/main/tests/android/icu/dev/test/calendar/JapaneseTest.java
+++ b/android_icu4j/src/main/tests/android/icu/dev/test/calendar/JapaneseTest.java
@@ -157,9 +157,9 @@
         Calendar cal = new JapaneseCalendar(loc);
         DateFormat enjformat = cal.getDateTimeFormat(0,0,new ULocale("en_JP@calendar=japanese"));
         DateFormat format = cal.getDateTimeFormat(0,0,loc);
-        ((SimpleDateFormat)format).applyPattern("y.M.d");  // Note: just 'y' doesn't work here.
+        ((SimpleDateFormat)format).applyPattern("y/M/d");  // Note: just 'y' doesn't work here.
         ParsePosition pos = new ParsePosition(0);
-        Date aDate = format.parse("1.1.9", pos); // after the start of heisei accession.  Jan 1, 1H wouldn't work  because it is actually showa 64
+        Date aDate = format.parse("1/5/9", pos); // after the start of Reiwa accession.  Jan 1, R1 wouldn't work  because it is actually Heisei 31
         String inEn = enjformat.format(aDate);
 
         cal.clear();
@@ -168,7 +168,7 @@
         int gotEra = cal.get(Calendar.ERA);
 
         int expectYear = 1;
-        int expectEra = JapaneseCalendar.CURRENT_ERA;
+        int expectEra = JapaneseCalendar.CURRENT_ERA;   // Reiwa
 
         if((gotYear != expectYear) || (gotEra != expectEra)) {
             errln("Expected year " + expectYear + ", era " + expectEra +", but got year " + gotYear + " and era " + gotEra + ", == " + inEn);
@@ -176,7 +176,7 @@
             logln("Got year " + gotYear + " and era " + gotEra + ", == " + inEn);
         }
 
-        // Test parse with missing era (should default to current era, heisei)
+        // Test parse with missing era (should default to current era)
         // Test parse with incomplete information
         logln("Testing parse w/ just year...");
         Calendar cal2 = new JapaneseCalendar(loc);
@@ -200,7 +200,7 @@
         gotYear = cal2.get(Calendar.YEAR);
         gotEra = cal2.get(Calendar.ERA);
         expectYear = 1;
-        expectEra = JapaneseCalendar.CURRENT_ERA;
+        expectEra = JapaneseCalendar.CURRENT_ERA;   // Reiwa
         if((gotYear != 1) || (gotEra != expectEra)) {
             errln("parse "+ samplestr + " of 'y' as Japanese Calendar, expected year " + expectYear +
                 " and era " + expectEra + ", but got year " + gotYear + " and era " + gotEra + " (Gregorian:" + str +")");
@@ -382,5 +382,37 @@
         doLimitsTest(jcal, null, cal.getTime());
         doTheoreticalLimitsTest(jcal, true);
     }
+
+    @Test
+    public void TestHeiseiToReiwa() {
+        Calendar cal = Calendar.getInstance();
+        cal.set(2019, Calendar.APRIL, 29);
+
+        DateFormat jfmt = DateFormat.getDateInstance(DateFormat.LONG, new ULocale("ja@calendar=japanese"));
+
+        // Android-changed: Old Android releases can optionally support the new Japanese era.
+        boolean isCurrentHeisei = JapaneseCalendar.CURRENT_ERA == JapaneseCalendar.HEISEI;
+        final String[] EXPECTED_FORMAT = new String[] {
+                "\u5E73\u621031\u5E744\u670829\u65E5",  // Heisei 31 April 29
+                "\u5E73\u621031\u5E744\u670830\u65E5",  // Heisei 31 April 30
+                isCurrentHeisei
+                    ? "\u5E73\u621031\u5E745\u67081\u65E5"    // Heisei 31 May 1
+                    : "\u4EE4\u548C1\u5E745\u67081\u65E5",    // Reiwa 1 May 1
+                isCurrentHeisei
+                    ? "\u5E73\u621031\u5E745\u67082\u65E5"    // Heisei 31 May 2
+                    : "\u4EE4\u548C1\u5E745\u67082\u65E5",    // Reiwa 1 May 2
+        };
+
+        for (int i = 0; i < EXPECTED_FORMAT.length; i++) {
+            Date d = cal.getTime();
+            String dateStr = jfmt.format(d);
+            if (!EXPECTED_FORMAT[i].equals(dateStr)) {
+                errln("Formatting year:" + cal.get(Calendar.YEAR) + " month:" + (cal.get(Calendar.MONTH) + 1)
+                        + " day:" + cal.get(Calendar.DATE) + " - expected: " + EXPECTED_FORMAT[i]
+                        + " / actual: " + dateStr);
+            }
+            cal.add(Calendar.DATE, 1);
+        }
+    }
 }
 
diff --git a/android_icu4j/src/main/tests/android/icu/dev/test/format/DataDrivenFormatTest.java b/android_icu4j/src/main/tests/android/icu/dev/test/format/DataDrivenFormatTest.java
index 2755bcc..5789e75 100644
--- a/android_icu4j/src/main/tests/android/icu/dev/test/format/DataDrivenFormatTest.java
+++ b/android_icu4j/src/main/tests/android/icu/dev/test/format/DataDrivenFormatTest.java
@@ -29,6 +29,7 @@
 import android.icu.text.DateFormat;
 import android.icu.text.SimpleDateFormat;
 import android.icu.util.Calendar;
+import android.icu.util.JapaneseCalendar;
 import android.icu.util.TimeZone;
 import android.icu.util.ULocale;
 
@@ -100,6 +101,14 @@
             String spec = currentCase.getString("spec");
             String date = currentCase.getString("date");
             String str = currentCase.getString("str");
+
+            // Android-changed: Old Android releases can optionally support the new Japanese era.
+            // Note that the value of CURRENT_ERA comes from the system image, the string "Reiwa"
+            // comes from test side binary resource file.
+            if (JapaneseCalendar.CURRENT_ERA == JapaneseCalendar.HEISEI
+                && "TestConsistentPivot".equals(testData.getName())) {
+                str = str.replace("Reiwa", "Heisei");
+            }
             
             Date fromDate = null;
             boolean useDate = false;
diff --git a/icu4c/source/test/intltest/incaltst.cpp b/icu4c/source/test/intltest/incaltst.cpp
index 1409d51..9bc7e5a 100644
--- a/icu4c/source/test/intltest/incaltst.cpp
+++ b/icu4c/source/test/intltest/incaltst.cpp
@@ -77,6 +77,7 @@
     CASE(7,TestPersian);
     CASE(8,TestPersianFormat);
     CASE(9,TestTaiwan);
+    CASE(10,TestJapaneseHeiseiToReiwa);
     default: name = ""; break;
     }
 }
@@ -626,23 +627,23 @@
         // Test simple parse/format with adopt
         UDate aDate = 0; 
         
-        // Test parse with missing era (should default to current era, heisei)
+        // Test parse with missing era (should default to current era)
         // Test parse with incomplete information
         logln("Testing parse w/ missing era...");
-        SimpleDateFormat *fmt = new SimpleDateFormat(UnicodeString("y.M.d"), Locale("ja_JP@calendar=japanese"), status);
+        SimpleDateFormat *fmt = new SimpleDateFormat(UnicodeString("y/M/d"), Locale("ja_JP@calendar=japanese"), status);
         CHECK(status, "creating date format instance");
         if(!fmt) { 
             errln("Couldn't create en_US instance");
         } else {
             UErrorCode s2 = U_ZERO_ERROR;
             cal2->clear();
-            UnicodeString samplestr("1.1.9");
+            UnicodeString samplestr("1/5/9");
             logln(UnicodeString() + "Test Year: " + samplestr);
             aDate = fmt->parse(samplestr, s2);
             ParsePosition pp=0;
             fmt->parse(samplestr, *cal2, pp);
-            CHECK(s2, "parsing the 1.1.9 string");
-            logln("*cal2 after 119 parse:");
+            CHECK(s2, "parsing the 1/5/9 string");
+            logln("*cal2 after 159 parse:");
             str.remove();
             fmt2->format(aDate, str);
             logln(UnicodeString() + "as Gregorian Calendar: " + str);
@@ -653,7 +654,7 @@
             int32_t expectYear = 1;
             int32_t expectEra = JapaneseCalendar::getCurrentEra();
             if((gotYear!=1) || (gotEra != expectEra)) {
-                errln(UnicodeString("parse "+samplestr+" of 'y.m.d' as Japanese Calendar, expected year ") + expectYear + 
+                errln(UnicodeString("parse "+samplestr+" of 'y/m/d' as Japanese Calendar, expected year ") + expectYear + 
                     UnicodeString(" and era ") + expectEra +", but got year " + gotYear + " and era " + gotEra + " (Gregorian:" + str +")");
             } else {            
                 logln(UnicodeString() + " year: " + gotYear + ", era: " + gotEra);
@@ -666,7 +667,7 @@
         // Test simple parse/format with adopt
         UDate aDate = 0; 
         
-        // Test parse with missing era (should default to current era, heisei)
+        // Test parse with missing era (should default to current era)
         // Test parse with incomplete information
         logln("Testing parse w/ just year...");
         SimpleDateFormat *fmt = new SimpleDateFormat(UnicodeString("y"), Locale("ja_JP@calendar=japanese"), status);
@@ -678,7 +679,7 @@
             cal2->clear();
             UnicodeString samplestr("1");
             logln(UnicodeString() + "Test Year: " + samplestr);
-            aDate = fmt->parse(samplestr, s2);
+            aDate = fmt->parse(samplestr, s2);  // Should be parsed as the first day of the current era
             ParsePosition pp=0;
             fmt->parse(samplestr, *cal2, pp);
             CHECK(s2, "parsing the 1 string");
@@ -691,7 +692,7 @@
             int32_t gotYear = cal2->get(UCAL_YEAR, s2);
             int32_t gotEra = cal2->get(UCAL_ERA, s2);
             int32_t expectYear = 1;
-            int32_t expectEra = 235; //JapaneseCalendar::kCurrentEra;
+            int32_t expectEra = JapaneseCalendar::getCurrentEra();
             if((gotYear!=1) || (gotEra != expectEra)) {
                 errln(UnicodeString("parse "+samplestr+" of 'y' as Japanese Calendar, expected year ") + expectYear + 
                     UnicodeString(" and era ") + expectEra +", but got year " + gotYear + " and era " + gotEra + " (Gregorian:" + str +")");
@@ -700,13 +701,47 @@
             }
             delete fmt;
         }
-    }    
+    }
 
     delete cal2;
     delete cal;
     delete fmt2;
 }
 
+void IntlCalendarTest::TestJapaneseHeiseiToReiwa() {
+    Calendar *cal;
+    UErrorCode status = U_ZERO_ERROR;
+    cal = Calendar::createInstance(status);
+    CHECK(status, UnicodeString("Creating default Gregorian Calendar"));
+    cal->set(2019, UCAL_APRIL, 29);
+
+    DateFormat *jfmt = DateFormat::createDateInstance(DateFormat::LONG, "ja@calendar=japanese");
+    CHECK(status, UnicodeString("Creating date format ja@calendar=japanese"))
+
+    const char* EXPECTED_FORMAT[4] = {
+        "\\u5E73\\u621031\\u5E744\\u670829\\u65E5", // Heisei 31 April 29
+        "\\u5E73\\u621031\\u5E744\\u670830\\u65E5", // Heisei 31 April 30
+        "\\u4EE4\\u548c1\\u5E745\\u67081\\u65E5",   // Reiwa 1 May 1
+        "\\u4EE4\\u548c1\\u5E745\\u67082\\u65E5"    // Reiwa 1 May 2
+    };
+
+    for (int32_t i = 0; i < 4; i++) {
+        UnicodeString dateStr;
+        UDate d = cal->getTime(status);
+        CHECK(status, UnicodeString("Get test date"));
+        jfmt->format(d, dateStr);
+        UnicodeString expected(UnicodeString(EXPECTED_FORMAT[i], -1, US_INV).unescape());
+        if (expected.compare(dateStr) != 0) {
+            errln(UnicodeString("Formatting year:") + cal->get(UCAL_YEAR, status) + " month:"
+                + cal->get(UCAL_MONTH, status) + " day:" + (cal->get(UCAL_DATE, status) + 1)
+                + " - expected: " + expected + " / actual: " + dateStr);
+        }
+        cal->add(UCAL_DATE, 1, status);
+        CHECK(status, UnicodeString("Add 1 day"));
+    }
+    delete jfmt;
+    delete cal;
+}
 
 
 
diff --git a/icu4c/source/test/intltest/incaltst.h b/icu4c/source/test/intltest/incaltst.h
index 628b6e4..52b121d 100644
--- a/icu4c/source/test/intltest/incaltst.h
+++ b/icu4c/source/test/intltest/incaltst.h
@@ -34,7 +34,8 @@
     void TestJapanese(void);
     void TestJapaneseFormat(void);
     void TestJapanese3860(void);
-    
+    void TestJapaneseHeiseiToReiwa(void);
+
     void TestPersian(void);
     void TestPersianFormat(void);
 
diff --git a/icu4c/source/test/testdata/format.txt b/icu4c/source/test/testdata/format.txt
index c0364e2..c598ade 100644
--- a/icu4c/source/test/testdata/format.txt
+++ b/icu4c/source/test/testdata/format.txt
@@ -494,35 +494,35 @@
                     "",
                     "PATTERN=G y",
                     "YEAR=8",
-                    "Heisei 8"
+                    "Reiwa 8"
                },
                {
                     "en_US@calendar=japanese",         
                     "",
                     "PATTERN=G yy",
                     "YEAR=8",
-                    "Heisei 08"
+                    "Reiwa 08"
                },
                {
                     "en_US@calendar=japanese",         
                     "",
                     "PATTERN=G yyy",
                     "YEAR=8",
-                    "Heisei 008"
+                    "Reiwa 008"
                },
                {
                     "en_US@calendar=japanese",         
                     "",
                     "PATTERN=G yyyy",
                     "YEAR=8",
-                    "Heisei 0008"
+                    "Reiwa 0008"
                },
                {
                     "en_US@calendar=japanese",         
                     "",
                     "PATTERN=G yyyyy",
                     "YEAR=8",
-                    "Heisei 00008"
+                    "Reiwa 00008"
                },
 
             }
diff --git a/icu4c/source/test/testdata/structLocale.txt b/icu4c/source/test/testdata/structLocale.txt
index bd3d2b9..e6372c3 100644
--- a/icu4c/source/test/testdata/structLocale.txt
+++ b/icu4c/source/test/testdata/structLocale.txt
@@ -25784,6 +25784,7 @@
                     "",
                     "",
                     "",
+                    "",
                 }
                 wide{
                     "",
@@ -26022,6 +26023,7 @@
                     "",
                     "",
                     "",
+                    "",
                 }
                 narrow{
                     "",
@@ -26260,6 +26262,7 @@
                     "",
                     "",
                     "",
+                    "",
                 }
             }
             intervalFormats{
diff --git a/icu4j/main/shared/data/testdata.jar b/icu4j/main/shared/data/testdata.jar
index 8f55a0e..7d7e1b0 100755
--- a/icu4j/main/shared/data/testdata.jar
+++ b/icu4j/main/shared/data/testdata.jar
Binary files differ
diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/calendar/JapaneseTest.java b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/calendar/JapaneseTest.java
index 6ec96f4..7015dd6 100644
--- a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/calendar/JapaneseTest.java
+++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/calendar/JapaneseTest.java
@@ -154,9 +154,9 @@
         Calendar cal = new JapaneseCalendar(loc);
         DateFormat enjformat = cal.getDateTimeFormat(0,0,new ULocale("en_JP@calendar=japanese"));
         DateFormat format = cal.getDateTimeFormat(0,0,loc);
-        ((SimpleDateFormat)format).applyPattern("y.M.d");  // Note: just 'y' doesn't work here.
+        ((SimpleDateFormat)format).applyPattern("y/M/d");  // Note: just 'y' doesn't work here.
         ParsePosition pos = new ParsePosition(0);
-        Date aDate = format.parse("1.1.9", pos); // after the start of heisei accession.  Jan 1, 1H wouldn't work  because it is actually showa 64
+        Date aDate = format.parse("1/5/9", pos); // after the start of Reiwa accession.  Jan 1, R1 wouldn't work  because it is actually Heisei 31
         String inEn = enjformat.format(aDate);
 
         cal.clear();
@@ -165,7 +165,7 @@
         int gotEra = cal.get(Calendar.ERA);
 
         int expectYear = 1;
-        int expectEra = JapaneseCalendar.CURRENT_ERA;
+        int expectEra = JapaneseCalendar.CURRENT_ERA;   // Reiwa
 
         if((gotYear != expectYear) || (gotEra != expectEra)) {
             errln("Expected year " + expectYear + ", era " + expectEra +", but got year " + gotYear + " and era " + gotEra + ", == " + inEn);
@@ -173,7 +173,7 @@
             logln("Got year " + gotYear + " and era " + gotEra + ", == " + inEn);
         }
 
-        // Test parse with missing era (should default to current era, heisei)
+        // Test parse with missing era (should default to current era)
         // Test parse with incomplete information
         logln("Testing parse w/ just year...");
         Calendar cal2 = new JapaneseCalendar(loc);
@@ -197,7 +197,7 @@
         gotYear = cal2.get(Calendar.YEAR);
         gotEra = cal2.get(Calendar.ERA);
         expectYear = 1;
-        expectEra = JapaneseCalendar.CURRENT_ERA;
+        expectEra = JapaneseCalendar.CURRENT_ERA;   // Reiwa
         if((gotYear != 1) || (gotEra != expectEra)) {
             errln("parse "+ samplestr + " of 'y' as Japanese Calendar, expected year " + expectYear +
                 " and era " + expectEra + ", but got year " + gotYear + " and era " + gotEra + " (Gregorian:" + str +")");
@@ -379,5 +379,37 @@
         doLimitsTest(jcal, null, cal.getTime());
         doTheoreticalLimitsTest(jcal, true);
     }
+
+    @Test
+    public void TestHeiseiToReiwa() {
+        Calendar cal = Calendar.getInstance();
+        cal.set(2019, Calendar.APRIL, 29);
+
+        DateFormat jfmt = DateFormat.getDateInstance(DateFormat.LONG, new ULocale("ja@calendar=japanese"));
+
+        // Android-changed: Old Android releases can optionally support the new Japanese era.
+        boolean isCurrentHeisei = JapaneseCalendar.CURRENT_ERA == JapaneseCalendar.HEISEI;
+        final String[] EXPECTED_FORMAT = new String[] {
+                "\u5E73\u621031\u5E744\u670829\u65E5",  // Heisei 31 April 29
+                "\u5E73\u621031\u5E744\u670830\u65E5",  // Heisei 31 April 30
+                isCurrentHeisei
+                    ? "\u5E73\u621031\u5E745\u67081\u65E5"    // Heisei 31 May 1
+                    : "\u4EE4\u548C1\u5E745\u67081\u65E5",    // Reiwa 1 May 1
+                isCurrentHeisei
+                    ? "\u5E73\u621031\u5E745\u67082\u65E5"    // Heisei 31 May 2
+                    : "\u4EE4\u548C1\u5E745\u67082\u65E5",    // Reiwa 1 May 2
+        };
+
+        for (int i = 0; i < EXPECTED_FORMAT.length; i++) {
+            Date d = cal.getTime();
+            String dateStr = jfmt.format(d);
+            if (!EXPECTED_FORMAT[i].equals(dateStr)) {
+                errln("Formatting year:" + cal.get(Calendar.YEAR) + " month:" + (cal.get(Calendar.MONTH) + 1)
+                        + " day:" + cal.get(Calendar.DATE) + " - expected: " + EXPECTED_FORMAT[i]
+                        + " / actual: " + dateStr);
+            }
+            cal.add(Calendar.DATE, 1);
+        }
+    }
 }
 
diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/DataDrivenFormatTest.java b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/DataDrivenFormatTest.java
index 91cf2ee..60b40a2 100644
--- a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/DataDrivenFormatTest.java
+++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/DataDrivenFormatTest.java
@@ -28,6 +28,7 @@
 import com.ibm.icu.text.DateFormat;
 import com.ibm.icu.text.SimpleDateFormat;
 import com.ibm.icu.util.Calendar;
+import com.ibm.icu.util.JapaneseCalendar;
 import com.ibm.icu.util.TimeZone;
 import com.ibm.icu.util.ULocale;
 
@@ -97,6 +98,14 @@
             String spec = currentCase.getString("spec");
             String date = currentCase.getString("date");
             String str = currentCase.getString("str");
+
+            // Android-changed: Old Android releases can optionally support the new Japanese era.
+            // Note that the value of CURRENT_ERA comes from the system image, the string "Reiwa"
+            // comes from test side binary resource file.
+            if (JapaneseCalendar.CURRENT_ERA == JapaneseCalendar.HEISEI
+                && "TestConsistentPivot".equals(testData.getName())) {
+                str = str.replace("Reiwa", "Heisei");
+            }
             
             Date fromDate = null;
             boolean useDate = false;