OpenJDK / jdk / jdk
changeset 50478:2e3f73b616c2
8202088: Japanese new era implementation
Reviewed-by: scolebourne, rriggs, nishjain, weijun
line wrap: on
line diff
--- a/src/java.base/share/classes/java/time/chrono/JapaneseEra.java Fri Jun 08 11:38:40 2018 -0700 +++ b/src/java.base/share/classes/java/time/chrono/JapaneseEra.java Wed Aug 09 14:54:37 2017 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2018, 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 @@ -123,14 +123,19 @@ */ 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 'NewEra' era (2019-05-01 - current) + * which has the value 3. + */ + private static final JapaneseEra NEWERA = 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 = HEISEI.getValue() + ERA_OFFSET; + private static final int N_ERA_CONSTANTS = NEWERA.getValue() + ERA_OFFSET; /** * Serialization version. @@ -148,6 +153,7 @@ KNOWN_ERAS[1] = TAISHO; KNOWN_ERAS[2] = SHOWA; KNOWN_ERAS[3] = HEISEI; + KNOWN_ERAS[4] = NEWERA; 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());
--- a/src/java.base/share/classes/java/util/JapaneseImperialCalendar.java Fri Jun 08 11:38:40 2018 -0700 +++ b/src/java.base/share/classes/java/util/JapaneseImperialCalendar.java Wed Aug 09 14:54:37 2017 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2018, 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-30T00:00:00 local time * 3 Showa 1926-12-25T00:00:00 local time * 4 Heisei 1989-01-08T00:00:00 local time + * 5 NewEra 2019-05-01T00:00:00 local time * ------------------------------------------------------ * }</pre> * @@ -71,8 +72,10 @@ * </pre> * where * <dl> - * <dt>{@code <name>:}<dd>the full name of the new era (non-ASCII characters allowed) - * <dt>{@code <abbr>:}<dd>the abbreviation of the new era (non-ASCII characters allowed) + * <dt>{@code <name>:}<dd>the full name of the new era (non-ASCII characters allowed, + * either in platform's native encoding or in Unicode escape notation, {@code \\uXXXX}) + * <dt>{@code <abbr>:}<dd>the abbreviation of the new era (non-ASCII characters allowed, + * either in platform's native encoding or in Unicode escape notation, {@code \\uXXXX}) * <dt>{@code <time['u']>:}<dd>the start time of the new era represented by * milliseconds from 1970-01-01T00:00:00 local time or UTC if {@code 'u'} is * appended to the milliseconds value. (ASCII digits only) @@ -125,6 +128,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) // Useful millisecond constants. Although ONE_DAY and ONE_WEEK can fit @@ -155,6 +163,9 @@ // 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 @@ -251,13 +262,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; @@ -1743,12 +1759,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()); @@ -1883,7 +1899,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) @@ -2367,7 +2383,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; } /**
--- a/src/java.base/share/classes/sun/text/resources/FormatData.java Fri Jun 08 11:38:40 2018 -0700 +++ b/src/java.base/share/classes/sun/text/resources/FormatData.java Wed Aug 09 14:54:37 2017 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2018, 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 @@ -106,6 +106,7 @@ "T", "S", "H", + "N", // NewEra }; // Japanese imperial calendar era strings @@ -115,6 +116,7 @@ "Taisho", "Showa", "Heisei", + "NewEra", // NewEra }; return new Object[][] {
--- a/src/java.base/share/classes/sun/text/resources/JavaTimeSupplementary.java Fri Jun 08 11:38:40 2018 -0700 +++ b/src/java.base/share/classes/sun/text/resources/JavaTimeSupplementary.java Wed Aug 09 14:54:37 2017 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2018, 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 @@ -159,6 +159,7 @@ "Taisho", "Showa", "Heisei", + "NewEra", // New Era }; final String[] sharedShortEras = {
--- a/src/java.base/share/classes/sun/util/calendar/Era.java Fri Jun 08 11:38:40 2018 -0700 +++ b/src/java.base/share/classes/sun/util/calendar/Era.java Wed Aug 09 14:54:37 2017 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2018, 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 @@ -48,6 +48,7 @@ * Taisho 1912-07-30T00:00:00 local time * Showa 1926-12-25T00:00:00 local time * Heisei 1989-01-08T00:00:00 local time + * NewEra 2019-05-01T00:00:00 local time * ----------------------------------------------------------------------- * }</pre> *
--- a/src/java.base/share/classes/sun/util/calendar/LocalGregorianCalendar.java Fri Jun 08 11:38:40 2018 -0700 +++ b/src/java.base/share/classes/sun/util/calendar/LocalGregorianCalendar.java Wed Aug 09 14:54:37 2017 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2018, 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 @@ -27,6 +27,8 @@ import java.security.AccessController; import java.util.TimeZone; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import sun.security.action.GetPropertyAction; /** @@ -41,11 +43,12 @@ new Era("Taisho", "T", -1812153600000L, true), new Era("Showa", "S", -1357603200000L, true), new Era("Heisei", "H", 600220800000L, true), + new Era("NewEra", "N", 1556668800000L, true), }; private static boolean isValidEra(Era newEra, Era[] eras) { Era last = eras[eras.length - 1]; - if (last.getSinceDate().getYear() >= newEra.getSinceDate().getYear()) { + if (last.getSince(null) >= newEra.getSince(null)) { return false; } // The new era name should be unique. Its abbr may not. @@ -173,7 +176,7 @@ return null; } String key = keyvalue[0].trim(); - String value = keyvalue[1].trim(); + String value = convertUnicodeEscape(keyvalue[1].trim()); switch (key) { case "name": eraName = value; @@ -203,6 +206,17 @@ return new Era(eraName, abbr, since, localTime); } + private static String convertUnicodeEscape(String src) { + Matcher m = Pattern.compile("\\\\u([0-9a-fA-F]{4})").matcher(src); + StringBuilder sb = new StringBuilder(); + while (m.find()) { + m.appendReplacement(sb, + Character.toString((char)Integer.parseUnsignedInt(m.group(1), 16))); + } + m.appendTail(sb); + return sb.toString(); + } + private LocalGregorianCalendar(String name, Era[] eras) { this.name = name; this.eras = eras;
--- a/src/java.base/share/classes/sun/util/locale/provider/CalendarNameProviderImpl.java Fri Jun 08 11:38:40 2018 -0700 +++ b/src/java.base/share/classes/sun/util/locale/provider/CalendarNameProviderImpl.java Wed Aug 09 14:54:37 2017 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2018, 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 @@ -35,8 +35,8 @@ import sun.util.calendar.Era; /** - * Concrete implementation of the {@link java.util.spi.CalendarDataProvider - * CalendarDataProvider} class for the JRE LocaleProviderAdapter. + * Concrete implementation of the {@link java.util.spi.CalendarNameProvider + * CalendarNameProvider} class for the JRE LocaleProviderAdapter. * * @author Masayoshi Okutsu * @author Naoto Sato @@ -77,28 +77,43 @@ if (field == DAY_OF_WEEK || field == YEAR) { --value; } - if (value < 0 || value > strings.length) { + if (value < 0) { return null; - } else if (value == strings.length) { + } else if (value >= strings.length) { if (field == ERA && "japanese".equals(calendarType)) { - // get the supplemental era, if any, specified through - // the property "jdk.calendar.japanese.supplemental.era" - // which is always the last element. Era[] jeras = CalendarSystem.forName("japanese").getEras(); - if (jeras.length == value) { - Era supEra = jeras[value - 1]; // 0-based index - if (javatime) { - return getBaseStyle(style) == NARROW_FORMAT ? - supEra.getAbbreviation() : - supEra.getName(); - } else { - return (style & LONG) != 0 ? - supEra.getName() : - supEra.getAbbreviation(); + if (value <= jeras.length) { + // Localized era name could not be retrieved from this provider. + // This can occur either for NewEra or SupEra. + // + // If it's CLDR provider, try COMPAT first, which is guaranteed to have + // the name for NewEra. + if (type == LocaleProviderAdapter.Type.CLDR) { + lr = LocaleProviderAdapter.forJRE().getLocaleResources(locale); + key = getResourceKeyFor(LocaleProviderAdapter.Type.JRE, + calendarType, field, style, javatime); + strings = + javatime ? lr.getJavaTimeNames(key) : lr.getCalendarNames(key); } + if (strings == null || value >= strings.length) { + // Get the default name for SupEra + Era supEra = jeras[value - 1]; // 0-based index + if (javatime) { + return getBaseStyle(style) == NARROW_FORMAT ? + supEra.getAbbreviation() : + supEra.getName(); + } else { + return (style & LONG) != 0 ? + supEra.getName() : + supEra.getAbbreviation(); + } + } + } else { + return null; } + } else { + return null; } - return null; } name = strings[value]; // If name is empty in standalone, try its `format' style. @@ -180,7 +195,7 @@ return map; } - private int getBaseStyle(int style) { + private static int getBaseStyle(int style) { return style & ~(SHORT_STANDALONE - SHORT_FORMAT); } @@ -261,6 +276,11 @@ } private String getResourceKey(String type, int field, int style, boolean javatime) { + return getResourceKeyFor(this.type, type, field, style, javatime); + } + + private static String getResourceKeyFor(LocaleProviderAdapter.Type adapterType, + String type, int field, int style, boolean javatime) { int baseStyle = getBaseStyle(style); boolean isStandalone = (style != baseStyle); @@ -284,7 +304,7 @@ // JRE and CLDR use different resource key conventions // due to historical reasons. (JRE DateFormatSymbols.getEras returns // abbreviations while other getShort*() return abbreviations.) - if (this.type == LocaleProviderAdapter.Type.JRE) { + if (adapterType == LocaleProviderAdapter.Type.JRE) { if (javatime) { if (baseStyle == LONG) { key.append("long."); @@ -336,7 +356,7 @@ return key.length() > 0 ? key.toString() : null; } - private String toStyleName(int baseStyle) { + private static String toStyleName(int baseStyle) { switch (baseStyle) { case SHORT: return "Abbreviations";
--- a/src/jdk.localedata/share/classes/sun/text/resources/ext/FormatData_ja.java Fri Jun 08 11:38:40 2018 -0700 +++ b/src/jdk.localedata/share/classes/sun/text/resources/ext/FormatData_ja.java Wed Aug 09 14:54:37 2017 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2018, 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 @@ -91,6 +91,7 @@ "\u5927\u6b63", // Taisho "\u662d\u548c", // Showa "\u5e73\u6210", // Heisei + "\u65b0\u5143\u53f7", // NewEra }; final String[] rocEras = { "\u6c11\u56fd\u524d",
--- a/src/jdk.localedata/share/classes/sun/text/resources/ext/JavaTimeSupplementary_ja.java Fri Jun 08 11:38:40 2018 -0700 +++ b/src/jdk.localedata/share/classes/sun/text/resources/ext/JavaTimeSupplementary_ja.java Wed Aug 09 14:54:37 2017 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2018, 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 @@ -154,6 +154,7 @@ "\u5927\u6b63", "\u662d\u548c", "\u5e73\u6210", + "\u65b0\u5143\u53f7", // NewEra }; final String[] sharedJavaTimeShortEras = {
--- a/test/jdk/java/text/Format/DateFormat/WeekDateTest.java Fri Jun 08 11:38:40 2018 -0700 +++ b/test/jdk/java/text/Format/DateFormat/WeekDateTest.java Wed Aug 09 14:54:37 2017 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2018, 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 @@ -137,20 +137,28 @@ Calendar jcal = Calendar.getInstance(TimeZone.getTimeZone("GMT"), new Locale("ja", "JP", "JP")); + String format = "2-W01-2"; // 2019-12-31 == N1-12-31 + int expectedYear = 2019; + // Check the current era, Heisei or NewEra + if (System.currentTimeMillis() < 1556668800000L) { + format = "21-W01-3"; // 2008-12-31 == H20-12-31 + expectedYear = 2008; + } jcal.setFirstDayOfWeek(MONDAY); jcal.setMinimalDaysInFirstWeek(4); SimpleDateFormat sdf = new SimpleDateFormat("Y-'W'ww-u"); sdf.setCalendar(jcal); - Date d = sdf.parse("21-W01-3"); // 2008-12-31 == H20-12-31 + Date d = sdf.parse(format); GregorianCalendar gcal = newCalendar(); gcal.setTime(d); - if (gcal.get(YEAR) != 2008 + if (gcal.get(YEAR) != expectedYear || gcal.get(MONTH) != DECEMBER || gcal.get(DAY_OF_MONTH) != 31) { - String s = String.format("noWeekDateSupport: got %04d-%02d-%02d, expected 2008-12-31%n", + String s = String.format("noWeekDateSupport: got %04d-%02d-%02d, expected %4d-12-31%n", gcal.get(YEAR), gcal.get(MONTH)+1, - gcal.get(DAY_OF_MONTH)); + gcal.get(DAY_OF_MONTH), + expectedYear); throw new RuntimeException(s); } }
--- a/test/jdk/java/time/tck/java/time/chrono/TCKJapaneseChronology.java Fri Jun 08 11:38:40 2018 -0700 +++ b/test/jdk/java/time/tck/java/time/chrono/TCKJapaneseChronology.java Wed Aug 09 14:54:37 2017 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + o Copyright (c) 2012, 2018, 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,7 @@ */ @Test public class TCKJapaneseChronology { + private static final int YDIFF_NEWERA = 2018; private static final int YDIFF_HEISEI = 1988; private static final int YDIFF_MEIJI = 1867; private static final int YDIFF_SHOWA = 1925; @@ -173,6 +174,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.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 +367,11 @@ @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 + {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}, @@ -548,6 +553,7 @@ { JapaneseEra.TAISHO, 0, "Taisho"}, { JapaneseEra.SHOWA, 1, "Showa"}, { JapaneseEra.HEISEI, 2, "Heisei"}, + { JapaneseEra.of(3), 3, "NewEra"}, // NEWERA }; } @@ -562,7 +568,7 @@ @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 +689,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"}, }; }
--- a/test/jdk/java/time/tck/java/time/chrono/TCKJapaneseEra.java Fri Jun 08 11:38:40 2018 -0700 +++ b/test/jdk/java/time/tck/java/time/chrono/TCKJapaneseEra.java Wed Aug 09 14:54:37 2017 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2018, 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 @@ -79,6 +79,7 @@ @DataProvider(name = "JapaneseEras") Object[][] data_of_eras() { return new Object[][] { + {JapaneseEra.of(3), "NewEra", 3}, // NEWERA {JapaneseEra.HEISEI, "Heisei", 2}, {JapaneseEra.SHOWA, "Showa", 1}, {JapaneseEra.TAISHO, "Taisho", 0}, @@ -91,7 +92,7 @@ return new Object[][] { {-2}, {-3}, - {3}, + {4}, {Integer.MIN_VALUE}, {Integer.MAX_VALUE}, };
--- a/test/jdk/java/time/test/java/time/chrono/TestJapaneseChronology.java Fri Jun 08 11:38:40 2018 -0700 +++ b/test/jdk/java/time/test/java/time/chrono/TestJapaneseChronology.java Wed Aug 09 14:54:37 2017 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2018, 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 @@ -58,6 +58,8 @@ { JapaneseEra.SHOWA, 1, 12, 25, 1926 }, { 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 }; } @@ -74,6 +76,8 @@ { JapaneseEra.SHOWA, 64, 7, 1, 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 }; } @@ -81,8 +85,8 @@ Object[][] rangeData() { 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, 3, 3}, + { ChronoField.YEAR_OF_ERA, 1, 1, 15, 999999999-2019}, // depends on the current era { ChronoField.DAY_OF_YEAR, 1, 1, 7, 366}, { ChronoField.YEAR, 1873, 1873, 999999999, 999999999}, }; @@ -105,7 +109,9 @@ { 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 }, // NEWERA + { JapaneseEra.of(3), Year.MAX_VALUE, 12, 31 }, // NEWERA }; } @@ -124,7 +130,10 @@ { JapaneseEra.SHOWA, 65 }, { JapaneseEra.HEISEI, -1 }, { JapaneseEra.HEISEI, 0 }, - { JapaneseEra.HEISEI, Year.MAX_VALUE }, + { JapaneseEra.HEISEI, 32 }, + { JapaneseEra.of(3), -1 }, // NEWERA + { JapaneseEra.of(3), 0 }, // NEWERA + { JapaneseEra.of(3), Year.MAX_VALUE }, // NEWERA }; } @@ -141,6 +150,9 @@ { JapaneseEra.SHOWA, 64, 8 }, { JapaneseEra.HEISEI, 1, 360 }, { JapaneseEra.HEISEI, 2, 366 }, + { JapaneseEra.HEISEI, 31, 121 }, + { JapaneseEra.of(3), 1, 246 }, // NEWERA + { JapaneseEra.of(3), 2, 367 }, // NEWERA }; }
--- a/test/jdk/java/time/test/java/time/chrono/TestUmmAlQuraChronology.java Fri Jun 08 11:38:40 2018 -0700 +++ b/test/jdk/java/time/test/java/time/chrono/TestUmmAlQuraChronology.java Wed Aug 09 14:54:37 2017 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2018, 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 @@ -775,8 +775,10 @@ {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"}, + {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"}, }; }
--- a/test/jdk/java/util/Calendar/Bug8007038.java Fri Jun 08 11:38:40 2018 -0700 +++ b/test/jdk/java/util/Calendar/Bug8007038.java Wed Aug 09 14:54:37 2017 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2018, 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 @@ -46,7 +46,7 @@ private static final int[][] eraMinMax = { {GregorianCalendar.BC, GregorianCalendar.AD}, {0, 1}, - {0, 4}, + {0, 5}, {0, 1}, {0, 1}, {0, 1},
--- a/test/jdk/java/util/Calendar/Builder/BuilderTest.java Fri Jun 08 11:38:40 2018 -0700 +++ b/test/jdk/java/util/Calendar/Builder/BuilderTest.java Wed Aug 09 14:54:37 2017 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2018, 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 @@ -27,6 +27,7 @@ * @summary Unit test for Calendar.Builder. */ +import java.time.LocalDateTime; import java.util.*; import static java.util.Calendar.*; @@ -132,7 +133,11 @@ .setFields(YEAR, 1, DAY_OF_YEAR, 1).build(); expected = Calendar.getInstance(jaJPJP); expected.clear(); - expected.set(1, JANUARY, 8); + if (LocalDateTime.now().isBefore(LocalDateTime.of(2019, 5, 1, 0, 0))) { + expected.set(1, JANUARY, 8); + } else { + expected.set(1, MAY, 1); + } check(cal, expected); // setLocale calb = builder();
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/jdk/java/util/Calendar/JapaneseEraNameTest.java Wed Aug 09 14:54:37 2017 -0700 @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2018, 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. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8202088 + * @summary Test the localized Japanese new era name (May 1st. 2019-) + * is retrieved no matter CLDR provider contains the name or not. + * @modules jdk.localedata + * @run testng/othervm JapaneseEraNameTest + * @run testng/othervm -Djava.locale.providers=CLDR JapaneseEraNameTest + */ + +import static java.util.Calendar.*; +import static java.util.Locale.*; +import java.util.Calendar; +import java.util.Locale; + +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; +import static org.testng.Assert.assertEquals; + +@Test +public class JapaneseEraNameTest { + static final Calendar c = new Calendar.Builder() + .setCalendarType("japanese") + .setFields(ERA, 5, YEAR, 1, MONTH, MAY, DAY_OF_MONTH, 1) + .build(); + + @DataProvider(name="names") + Object[][] names() { + return new Object[][] { + // type, locale, name + { LONG, JAPAN, "\u65b0\u5143\u53f7" }, // NewEra + { LONG, US, "NewEra" }, + { SHORT, JAPAN, "N" }, + { SHORT, US, "N" }, + }; + } + + @Test(dataProvider="names") + public void testJapaneseNewEraName(int type, Locale locale, String expected) { + assertEquals(c.getDisplayName(ERA, type, locale), expected); + } +}
--- a/test/jdk/java/util/Calendar/NarrowNamesTest.java Fri Jun 08 11:38:40 2018 -0700 +++ b/test/jdk/java/util/Calendar/NarrowNamesTest.java Wed Aug 09 14:54:37 2017 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2018, 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 @@ -21,6 +21,7 @@ * questions. */ +import java.time.LocalDateTime; import java.util.*; import static java.util.GregorianCalendar.*; @@ -49,7 +50,9 @@ HOUR_OF_DAY, 10); test(US, AM_PM, "p", HOUR_OF_DAY, 23); - test(JAJPJP, DAY_OF_WEEK, "\u65e5", + test(JAJPJP, DAY_OF_WEEK, + LocalDateTime.now().isBefore(LocalDateTime.of(2019, 5, 1, 0, 0)) ? + "\u65e5" : "\u706b", // "Sun" for HEISEI, "Tue" for NEWERA YEAR, 24, MONTH, DECEMBER, DAY_OF_MONTH, 23); test(THTH, MONTH, NARROW_STANDALONE, "\u0e18.\u0e04.", YEAR, 2555, MONTH, DECEMBER, DAY_OF_MONTH, 5);
--- a/test/jdk/java/util/Calendar/SupplementalJapaneseEraTest.java Fri Jun 08 11:38:40 2018 -0700 +++ b/test/jdk/java/util/Calendar/SupplementalJapaneseEraTest.java Wed Aug 09 14:54:37 2017 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2018, 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,8 +50,8 @@ public class SupplementalJapaneseEraTest { private static final Locale WAREKI_LOCALE = Locale.forLanguageTag("ja-JP-u-ca-japanese"); - private static final String NEW_ERA_NAME = "NewEra"; - private static final String NEW_ERA_ABBR = "N.E."; + private static final String SUP_ERA_NAME = "SupEra"; + private static final String SUP_ERA_ABBR = "S.E."; private static int errors = 0; public static void main(String[] args) { @@ -62,6 +62,7 @@ Calendar cal = new Calendar.Builder() .setCalendarType("japanese") .setTimeZone(TimeZone.getTimeZone("GMT")) + .setFields(ERA, 5) .setDate(200, FEBRUARY, 11) .build(); System.out.println(cal.getTimeInMillis()); @@ -95,10 +96,9 @@ private static void testProperty() { Calendar jcal = new Calendar.Builder() .setCalendarType("japanese") - .setFields(YEAR, 1, DAY_OF_YEAR, 1) + .setFields(ERA, 6, YEAR, 1, DAY_OF_YEAR, 1) .build(); Date firstDayOfEra = jcal.getTime(); - jcal.set(ERA, jcal.get(ERA) - 1); // previous era jcal.set(YEAR, 1); jcal.set(DAY_OF_YEAR, 1); @@ -113,7 +113,7 @@ // test long era name sdf = new SimpleDateFormat("GGGG y-MM-dd", WAREKI_LOCALE); got = sdf.format(firstDayOfEra); - expected = NEW_ERA_NAME + " 1-02-11"; + expected = SUP_ERA_NAME + " 1-02-11"; if (!expected.equals(got)) { System.err.printf("GGGG y-MM-dd: got=\"%s\", expected=\"%s\"%n", got, expected); errors++; @@ -122,7 +122,7 @@ // test era abbreviation sdf = new SimpleDateFormat("G y-MM-dd", WAREKI_LOCALE); got = sdf.format(firstDayOfEra); - expected = NEW_ERA_ABBR+" 1-02-11"; + expected = SUP_ERA_ABBR + " 1-02-11"; if (!expected.equals(got)) { System.err.printf("G y-MM-dd: got=\"%s\", expected=\"%s\"%n", got, expected); errors++; @@ -139,30 +139,30 @@ // test java.time.chrono.JapaneseEra JapaneseDate jdate = JapaneseDate.of(year, 2, 11); got = jdate.toString(); - expected = "Japanese " + NEW_ERA_NAME + " 1-02-11"; + expected = "Japanese " + SUP_ERA_NAME + " 1-02-11"; if (!expected.equals(got)) { System.err.printf("JapaneseDate: got=\"%s\", expected=\"%s\"%n", got, expected); errors++; } JapaneseEra jera = jdate.getEra(); got = jera.getDisplayName(TextStyle.FULL, Locale.US); - if (!NEW_ERA_NAME.equals(got)) { - System.err.printf("JapaneseEra (FULL): got=\"%s\", expected=\"%s\"%n", got, NEW_ERA_NAME); + if (!SUP_ERA_NAME.equals(got)) { + System.err.printf("JapaneseEra (FULL): got=\"%s\", expected=\"%s\"%n", got, SUP_ERA_NAME); errors++; } got = jera.getDisplayName(TextStyle.SHORT, Locale.US); - if (!NEW_ERA_NAME.equals(got)) { - System.err.printf("JapaneseEra (SHORT): got=\"%s\", expected=\"%s\"%n", got, NEW_ERA_NAME); + if (!SUP_ERA_NAME.equals(got)) { + System.err.printf("JapaneseEra (SHORT): got=\"%s\", expected=\"%s\"%n", got, SUP_ERA_NAME); errors++; } got = jera.getDisplayName(TextStyle.NARROW, Locale.US); - if (!NEW_ERA_ABBR.equals(got)) { - System.err.printf("JapaneseEra (NARROW): got=\"%s\", expected=\"%s\"%n", got, NEW_ERA_ABBR); + if (!SUP_ERA_ABBR.equals(got)) { + System.err.printf("JapaneseEra (NARROW): got=\"%s\", expected=\"%s\"%n", got, SUP_ERA_ABBR); errors++; } got = jera.getDisplayName(TextStyle.NARROW_STANDALONE, Locale.US); - if (!NEW_ERA_ABBR.equals(got)) { - System.err.printf("JapaneseEra (NARROW_STANDALONE): got=\"%s\", expected=\"%s\"%n", got, NEW_ERA_ABBR); + if (!SUP_ERA_ABBR.equals(got)) { + System.err.printf("JapaneseEra (NARROW_STANDALONE): got=\"%s\", expected=\"%s\"%n", got, SUP_ERA_ABBR); errors++; } @@ -172,7 +172,7 @@ .withLocale(Locale.US) .withChronology(JapaneseChronology.INSTANCE) .format(jdate); - expected = NEW_ERA_NAME + " " + NEW_ERA_NAME + " " + NEW_ERA_ABBR; + expected = SUP_ERA_NAME + " " + SUP_ERA_NAME + " " + SUP_ERA_ABBR; if (!expected.equals(got)) { System.err.printf("java.time formatter full/short/narrow names: got=\"%s\", expected=\"%s\"%n", got, expected); errors++;
--- a/test/jdk/java/util/Calendar/SupplementalJapaneseEraTest.sh Fri Jun 08 11:38:40 2018 -0700 +++ b/test/jdk/java/util/Calendar/SupplementalJapaneseEraTest.sh Wed Aug 09 14:54:37 2017 -0700 @@ -1,5 +1,5 @@ # -# Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2014, 2018, 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 @@ -34,8 +34,8 @@ SINCE=`${TESTJAVA}/bin/java -cp "${TESTCLASSES}" SupplementalJapaneseEraTest -s` echo "Tests with valid property values..." -for P in "name=NewEra,abbr=N.E.,since=$SINCE" \ - "name = NewEra, abbr = N.E., since = $SINCE" +for P in "name=SupEra,abbr=S.E.,since=$SINCE" \ + "name = SupEra, abbr = S.E., since = $SINCE" do if ${TESTJAVA}/bin/java ${TESTVMOPTS} -cp "${TESTCLASSES}" \ -D$PROPERTY="$P" SupplementalJapaneseEraTest -t; then @@ -51,17 +51,17 @@ ERA=`${TESTJAVA}/bin/java -cp "${TESTCLASSES}" SupplementalJapaneseEraTest -e` echo "Tests with invalid property values..." -for P in "foo=Bar,name=NewEra,abbr=N.E.,since=$SINCE" \ - "=NewEra,abbr=N.E.,since=$SINCE" \ - "=,abbr=N.E.,since=$SINCE" \ - "name,abbr=N.E.,since=$SINCE" \ - "abbr=N.E.,since=$SINCE" \ - "name=NewEra,since=$SINCE" \ - "name=,abbr=N.E.,since=$SINCE" \ - "name=NewEra,abbr=,since=$SINCE" \ - "name=NewEra,abbr=N.E." \ - "name=NewEra,abbr=N.E.,since=0" \ - "name=NewEra,abbr=N.E.,since=9223372036854775808" # Long.MAX_VALUE+1 +for P in "foo=Bar,name=SupEra,abbr=S.E.,since=$SINCE" \ + "=SupEra,abbr=S.E.,since=$SINCE" \ + "=,abbr=S.E.,since=$SINCE" \ + "name,abbr=S.E.,since=$SINCE" \ + "abbr=S.E.,since=$SINCE" \ + "name=SupEra,since=$SINCE" \ + "name=,abbr=S.E.,since=$SINCE" \ + "name=SupEra,abbr=,since=$SINCE" \ + "name=SupEra,abbr=S.E." \ + "name=SupEra,abbr=S.E.,since=0" \ + "name=SupEra,abbr=S.E.,since=9223372036854775808" # Long.MAX_VALUE+1 do if ${TESTJAVA}/bin/java ${TESTVMOPTS} -cp "${TESTCLASSES}" \ -D$PROPERTY="$P" SupplementalJapaneseEraTest -b "$ERA"; then
--- a/test/jdk/java/util/Calendar/ZoneOffsets.java Fri Jun 08 11:38:40 2018 -0700 +++ b/test/jdk/java/util/Calendar/ZoneOffsets.java Wed Aug 09 14:54:37 2017 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2018, 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 @@ -192,6 +192,7 @@ cal2.setTimeZone(tz2); cal2.clear(); cal2.set(2005, MARCH, 11); + adjustJapaneseEra(cal2); // test5: set only ZONE_OFFSET in non-lenient cal2.set(ZONE_OFFSET, gmtOffset); if (t1 != cal2.getTime().getTime() || dst != cal2.get(DST_OFFSET)) { @@ -201,6 +202,7 @@ cal2.setTimeZone(tz3); cal2.clear(); cal2.set(2005, MARCH, 11); + adjustJapaneseEra(cal2); // test6: set only DST_OFFSET in non-lenient cal2.set(DST_OFFSET, dstOffset); if (t1 != cal2.getTime().getTime() || gmt != cal2.get(ZONE_OFFSET)) { @@ -210,6 +212,7 @@ cal2.setTimeZone(tz2); cal2.clear(); cal2.set(2005, MARCH, 11); + adjustJapaneseEra(cal2); // test7: set both ZONE_OFFSET and DST_OFFSET in non-lenient cal2.set(ZONE_OFFSET, gmtOffset); cal2.set(DST_OFFSET, dstOffset); @@ -220,6 +223,7 @@ cal2.setTimeZone(tz3); cal2.clear(); cal2.set(2005, MARCH, 11); + adjustJapaneseEra(cal2); // test8: set both ZONE_OFFSET and DST_OFFSET in non-lenient cal2.set(ZONE_OFFSET, gmtOffset); cal2.set(DST_OFFSET, dstOffset); @@ -234,4 +238,16 @@ + ", gmtOffset=" + gmtOffset + ", dstOffset=" + dstOffset + ", cal1 time=" + t1 + ", cal2 time=" + cal2.getTime().getTime()); } + + private static void adjustJapaneseEra(Calendar cal) { + // In case of Japanese calendar, explicitly set the last era; NEWERA so that + // year 2005 won't throw exception + if (!cal.isLenient() && + cal.getCalendarType().equals("japanese") && + System.currentTimeMillis() < 1556668800000L) { // Current time not in NEWERA + cal.set(Calendar.ERA, 5); + cal.add(Calendar.YEAR, -30); // -30: Subtract year-length of HEISEI era + } + return; + } }