8202088: Japanese new era implementation

Reviewed-by: scolebourne, rriggs, nishjain, weijun
This commit is contained in:
Naoto Sato 2017-08-09 14:54:37 -07:00
parent 307f2c4550
commit ec4b6a477f
21 changed files with 277 additions and 96 deletions

View file

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -123,14 +123,19 @@ public final class JapaneseEra
*/ */
public static final JapaneseEra SHOWA = new JapaneseEra(1, LocalDate.of(1926, 12, 25)); 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. * which has the value 2.
*/ */
public static final JapaneseEra HEISEI = new JapaneseEra(2, LocalDate.of(1989, 1, 8)); 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. // The number of predefined JapaneseEra constants.
// There may be a supplemental era defined by the property. // 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. * Serialization version.
@ -148,6 +153,7 @@ public final class JapaneseEra
KNOWN_ERAS[1] = TAISHO; KNOWN_ERAS[1] = TAISHO;
KNOWN_ERAS[2] = SHOWA; KNOWN_ERAS[2] = SHOWA;
KNOWN_ERAS[3] = HEISEI; KNOWN_ERAS[3] = HEISEI;
KNOWN_ERAS[4] = NEWERA;
for (int i = N_ERA_CONSTANTS; i < ERA_CONFIG.length; i++) { for (int i = N_ERA_CONSTANTS; i < ERA_CONFIG.length; i++) {
CalendarDate date = ERA_CONFIG[i].getSinceDate(); CalendarDate date = ERA_CONFIG[i].getSinceDate();
LocalDate isoDate = LocalDate.of(date.getYear(), date.getMonth(), date.getDayOfMonth()); LocalDate isoDate = LocalDate.of(date.getYear(), date.getMonth(), date.getDayOfMonth());

View file

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -50,6 +50,7 @@ import sun.util.calendar.ZoneInfo;
* 2 Taisho 1912-07-30T00:00:00 local time * 2 Taisho 1912-07-30T00:00:00 local time
* 3 Showa 1926-12-25T00:00:00 local time * 3 Showa 1926-12-25T00:00:00 local time
* 4 Heisei 1989-01-08T00:00:00 local time * 4 Heisei 1989-01-08T00:00:00 local time
* 5 NewEra 2019-05-01T00:00:00 local time
* ------------------------------------------------------ * ------------------------------------------------------
* }</pre> * }</pre>
* *
@ -71,8 +72,10 @@ import sun.util.calendar.ZoneInfo;
* </pre> * </pre>
* where * where
* <dl> * <dl>
* <dt>{@code <name>:}<dd>the full name of the new era (non-ASCII characters allowed) * <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) * 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 * <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 * milliseconds from 1970-01-01T00:00:00 local time or UTC if {@code 'u'} is
* appended to the milliseconds value. (ASCII digits only) * appended to the milliseconds value. (ASCII digits only)
@ -125,6 +128,11 @@ class JapaneseImperialCalendar extends Calendar {
*/ */
public static final int HEISEI = 4; public static final int HEISEI = 4;
/**
* The ERA constant designating the NewEra era.
*/
private static final int NEWERA = 5;
private static final int EPOCH_OFFSET = 719163; // Fixed date of January 1, 1970 (Gregorian) private static final int EPOCH_OFFSET = 719163; // Fixed date of January 1, 1970 (Gregorian)
// Useful millisecond constants. Although ONE_DAY and ONE_WEEK can fit // Useful millisecond constants. Although ONE_DAY and ONE_WEEK can fit
@ -155,6 +163,9 @@ class JapaneseImperialCalendar extends Calendar {
// Fixed date of the first date of each era. // Fixed date of the first date of each era.
private static final long[] sinceFixedDates; private static final long[] sinceFixedDates;
// The current era
private static final int currentEra;
/* /*
* <pre> * <pre>
* Greatest Least * Greatest Least
@ -251,13 +262,18 @@ class JapaneseImperialCalendar extends Calendar {
// eras[BEFORE_MEIJI] and sinceFixedDate[BEFORE_MEIJI] are the // eras[BEFORE_MEIJI] and sinceFixedDate[BEFORE_MEIJI] are the
// same as Gregorian. // same as Gregorian.
int index = BEFORE_MEIJI; int index = BEFORE_MEIJI;
int current = index;
sinceFixedDates[index] = gcal.getFixedDate(BEFORE_MEIJI_ERA.getSinceDate()); sinceFixedDates[index] = gcal.getFixedDate(BEFORE_MEIJI_ERA.getSinceDate());
eras[index++] = BEFORE_MEIJI_ERA; eras[index++] = BEFORE_MEIJI_ERA;
for (Era e : es) { for (Era e : es) {
if(e.getSince(TimeZone.NO_TIMEZONE) < System.currentTimeMillis()) {
current = index;
}
CalendarDate d = e.getSinceDate(); CalendarDate d = e.getSinceDate();
sinceFixedDates[index] = gcal.getFixedDate(d); sinceFixedDates[index] = gcal.getFixedDate(d);
eras[index++] = e; eras[index++] = e;
} }
currentEra = current;
LEAST_MAX_VALUES[ERA] = MAX_VALUES[ERA] = eras.length - 1; LEAST_MAX_VALUES[ERA] = MAX_VALUES[ERA] = eras.length - 1;
@ -1743,12 +1759,12 @@ class JapaneseImperialCalendar extends Calendar {
} }
} else if (transitionYear) { } else if (transitionYear) {
if (jdate.getYear() == 1) { 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 // that there are multiple transitions in a
// year. Historically there was such // year. Historically there was such
// case. There might be such case again in the // case. There might be such case again in the
// future. // future.
if (era > HEISEI) { if (era > NEWERA) {
CalendarDate pd = eras[era - 1].getSinceDate(); CalendarDate pd = eras[era - 1].getSinceDate();
if (normalizedYear == pd.getYear()) { if (normalizedYear == pd.getYear()) {
d.setMonth(pd.getMonth()).setDayOfMonth(pd.getDayOfMonth()); d.setMonth(pd.getMonth()).setDayOfMonth(pd.getDayOfMonth());
@ -1883,7 +1899,7 @@ class JapaneseImperialCalendar extends Calendar {
year = isSet(YEAR) ? internalGet(YEAR) : 1; year = isSet(YEAR) ? internalGet(YEAR) : 1;
} else { } else {
if (isSet(YEAR)) { if (isSet(YEAR)) {
era = eras.length - 1; era = currentEra;
year = internalGet(YEAR); year = internalGet(YEAR);
} else { } else {
// Equivalent to 1970 (Gregorian) // Equivalent to 1970 (Gregorian)
@ -2367,7 +2383,7 @@ class JapaneseImperialCalendar extends Calendar {
* default ERA is the current era, but a zero (unset) ERA means before Meiji. * default ERA is the current era, but a zero (unset) ERA means before Meiji.
*/ */
private int internalGetEra() { private int internalGetEra() {
return isSet(ERA) ? internalGet(ERA) : eras.length - 1; return isSet(ERA) ? internalGet(ERA) : currentEra;
} }
/** /**

View file

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -106,6 +106,7 @@ public class FormatData extends ParallelListResourceBundle {
"T", "T",
"S", "S",
"H", "H",
"N", // NewEra
}; };
// Japanese imperial calendar era strings // Japanese imperial calendar era strings
@ -115,6 +116,7 @@ public class FormatData extends ParallelListResourceBundle {
"Taisho", "Taisho",
"Showa", "Showa",
"Heisei", "Heisei",
"NewEra", // NewEra
}; };
return new Object[][] { return new Object[][] {

View file

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -159,6 +159,7 @@ public class JavaTimeSupplementary extends OpenListResourceBundle {
"Taisho", "Taisho",
"Showa", "Showa",
"Heisei", "Heisei",
"NewEra", // New Era
}; };
final String[] sharedShortEras = { final String[] sharedShortEras = {

View file

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -48,6 +48,7 @@ import java.util.TimeZone;
* Taisho 1912-07-30T00:00:00 local time * Taisho 1912-07-30T00:00:00 local time
* Showa 1926-12-25T00:00:00 local time * Showa 1926-12-25T00:00:00 local time
* Heisei 1989-01-08T00:00:00 local time * Heisei 1989-01-08T00:00:00 local time
* NewEra 2019-05-01T00:00:00 local time
* ----------------------------------------------------------------------- * -----------------------------------------------------------------------
* }</pre> * }</pre>
* *

View file

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -27,6 +27,8 @@ package sun.util.calendar;
import java.security.AccessController; import java.security.AccessController;
import java.util.TimeZone; import java.util.TimeZone;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import sun.security.action.GetPropertyAction; import sun.security.action.GetPropertyAction;
/** /**
@ -41,11 +43,12 @@ public class LocalGregorianCalendar extends BaseCalendar {
new Era("Taisho", "T", -1812153600000L, true), new Era("Taisho", "T", -1812153600000L, true),
new Era("Showa", "S", -1357603200000L, true), new Era("Showa", "S", -1357603200000L, true),
new Era("Heisei", "H", 600220800000L, true), new Era("Heisei", "H", 600220800000L, true),
new Era("NewEra", "N", 1556668800000L, true),
}; };
private static boolean isValidEra(Era newEra, Era[] eras) { private static boolean isValidEra(Era newEra, Era[] eras) {
Era last = eras[eras.length - 1]; Era last = eras[eras.length - 1];
if (last.getSinceDate().getYear() >= newEra.getSinceDate().getYear()) { if (last.getSince(null) >= newEra.getSince(null)) {
return false; return false;
} }
// The new era name should be unique. Its abbr may not. // The new era name should be unique. Its abbr may not.
@ -173,7 +176,7 @@ public class LocalGregorianCalendar extends BaseCalendar {
return null; return null;
} }
String key = keyvalue[0].trim(); String key = keyvalue[0].trim();
String value = keyvalue[1].trim(); String value = convertUnicodeEscape(keyvalue[1].trim());
switch (key) { switch (key) {
case "name": case "name":
eraName = value; eraName = value;
@ -203,6 +206,17 @@ public class LocalGregorianCalendar extends BaseCalendar {
return new Era(eraName, abbr, since, localTime); 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) { private LocalGregorianCalendar(String name, Era[] eras) {
this.name = name; this.name = name;
this.eras = eras; this.eras = eras;

View file

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -35,8 +35,8 @@ import sun.util.calendar.CalendarSystem;
import sun.util.calendar.Era; import sun.util.calendar.Era;
/** /**
* Concrete implementation of the {@link java.util.spi.CalendarDataProvider * Concrete implementation of the {@link java.util.spi.CalendarNameProvider
* CalendarDataProvider} class for the JRE LocaleProviderAdapter. * CalendarNameProvider} class for the JRE LocaleProviderAdapter.
* *
* @author Masayoshi Okutsu * @author Masayoshi Okutsu
* @author Naoto Sato * @author Naoto Sato
@ -77,28 +77,43 @@ public class CalendarNameProviderImpl extends CalendarNameProvider implements Av
if (field == DAY_OF_WEEK || field == YEAR) { if (field == DAY_OF_WEEK || field == YEAR) {
--value; --value;
} }
if (value < 0 || value > strings.length) { if (value < 0) {
return null; return null;
} else if (value == strings.length) { } else if (value >= strings.length) {
if (field == ERA && "japanese".equals(calendarType)) { 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(); Era[] jeras = CalendarSystem.forName("japanese").getEras();
if (jeras.length == value) { if (value <= jeras.length) {
Era supEra = jeras[value - 1]; // 0-based index // Localized era name could not be retrieved from this provider.
if (javatime) { // This can occur either for NewEra or SupEra.
return getBaseStyle(style) == NARROW_FORMAT ? //
supEra.getAbbreviation() : // If it's CLDR provider, try COMPAT first, which is guaranteed to have
supEra.getName(); // the name for NewEra.
} else { if (type == LocaleProviderAdapter.Type.CLDR) {
return (style & LONG) != 0 ? lr = LocaleProviderAdapter.forJRE().getLocaleResources(locale);
supEra.getName() : key = getResourceKeyFor(LocaleProviderAdapter.Type.JRE,
supEra.getAbbreviation(); 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]; name = strings[value];
// If name is empty in standalone, try its `format' style. // If name is empty in standalone, try its `format' style.
@ -180,7 +195,7 @@ public class CalendarNameProviderImpl extends CalendarNameProvider implements Av
return map; return map;
} }
private int getBaseStyle(int style) { private static int getBaseStyle(int style) {
return style & ~(SHORT_STANDALONE - SHORT_FORMAT); return style & ~(SHORT_STANDALONE - SHORT_FORMAT);
} }
@ -261,6 +276,11 @@ public class CalendarNameProviderImpl extends CalendarNameProvider implements Av
} }
private String getResourceKey(String type, int field, int style, boolean javatime) { 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); int baseStyle = getBaseStyle(style);
boolean isStandalone = (style != baseStyle); boolean isStandalone = (style != baseStyle);
@ -284,7 +304,7 @@ public class CalendarNameProviderImpl extends CalendarNameProvider implements Av
// JRE and CLDR use different resource key conventions // JRE and CLDR use different resource key conventions
// due to historical reasons. (JRE DateFormatSymbols.getEras returns // due to historical reasons. (JRE DateFormatSymbols.getEras returns
// abbreviations while other getShort*() return abbreviations.) // abbreviations while other getShort*() return abbreviations.)
if (this.type == LocaleProviderAdapter.Type.JRE) { if (adapterType == LocaleProviderAdapter.Type.JRE) {
if (javatime) { if (javatime) {
if (baseStyle == LONG) { if (baseStyle == LONG) {
key.append("long."); key.append("long.");
@ -336,7 +356,7 @@ public class CalendarNameProviderImpl extends CalendarNameProvider implements Av
return key.length() > 0 ? key.toString() : null; return key.length() > 0 ? key.toString() : null;
} }
private String toStyleName(int baseStyle) { private static String toStyleName(int baseStyle) {
switch (baseStyle) { switch (baseStyle) {
case SHORT: case SHORT:
return "Abbreviations"; return "Abbreviations";

View file

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -91,6 +91,7 @@ public class FormatData_ja extends ParallelListResourceBundle {
"\u5927\u6b63", // Taisho "\u5927\u6b63", // Taisho
"\u662d\u548c", // Showa "\u662d\u548c", // Showa
"\u5e73\u6210", // Heisei "\u5e73\u6210", // Heisei
"\u65b0\u5143\u53f7", // NewEra
}; };
final String[] rocEras = { final String[] rocEras = {
"\u6c11\u56fd\u524d", "\u6c11\u56fd\u524d",

View file

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -154,6 +154,7 @@ public class JavaTimeSupplementary_ja extends OpenListResourceBundle {
"\u5927\u6b63", "\u5927\u6b63",
"\u662d\u548c", "\u662d\u548c",
"\u5e73\u6210", "\u5e73\u6210",
"\u65b0\u5143\u53f7", // NewEra
}; };
final String[] sharedJavaTimeShortEras = { final String[] sharedJavaTimeShortEras = {

View file

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -137,20 +137,28 @@ public class WeekDateTest {
Calendar jcal = Calendar.getInstance(TimeZone.getTimeZone("GMT"), Calendar jcal = Calendar.getInstance(TimeZone.getTimeZone("GMT"),
new Locale("ja", "JP", "JP")); 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.setFirstDayOfWeek(MONDAY);
jcal.setMinimalDaysInFirstWeek(4); jcal.setMinimalDaysInFirstWeek(4);
SimpleDateFormat sdf = new SimpleDateFormat("Y-'W'ww-u"); SimpleDateFormat sdf = new SimpleDateFormat("Y-'W'ww-u");
sdf.setCalendar(jcal); sdf.setCalendar(jcal);
Date d = sdf.parse("21-W01-3"); // 2008-12-31 == H20-12-31 Date d = sdf.parse(format);
GregorianCalendar gcal = newCalendar(); GregorianCalendar gcal = newCalendar();
gcal.setTime(d); gcal.setTime(d);
if (gcal.get(YEAR) != 2008 if (gcal.get(YEAR) != expectedYear
|| gcal.get(MONTH) != DECEMBER || gcal.get(MONTH) != DECEMBER
|| gcal.get(DAY_OF_MONTH) != 31) { || 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(YEAR),
gcal.get(MONTH)+1, gcal.get(MONTH)+1,
gcal.get(DAY_OF_MONTH)); gcal.get(DAY_OF_MONTH),
expectedYear);
throw new RuntimeException(s); throw new RuntimeException(s);
} }
} }

View file

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -111,6 +111,7 @@ import org.testng.annotations.Test;
*/ */
@Test @Test
public class TCKJapaneseChronology { public class TCKJapaneseChronology {
private static final int YDIFF_NEWERA = 2018;
private static final int YDIFF_HEISEI = 1988; private static final int YDIFF_HEISEI = 1988;
private static final int YDIFF_MEIJI = 1867; private static final int YDIFF_MEIJI = 1867;
private static final int YDIFF_SHOWA = 1925; private static final int YDIFF_SHOWA = 1925;
@ -173,6 +174,7 @@ public class TCKJapaneseChronology {
@DataProvider(name="createByEra") @DataProvider(name="createByEra")
Object[][] data_createByEra() { Object[][] data_createByEra() {
return new Object[][] { 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, 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.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)}, {JapaneseEra.MEIJI, 1874 - YDIFF_MEIJI, 2, 28, 59, LocalDate.of(1874, 2, 28)},
@ -365,8 +367,11 @@ public class TCKJapaneseChronology {
@DataProvider(name="prolepticYear") @DataProvider(name="prolepticYear")
Object[][] data_prolepticYear() { Object[][] data_prolepticYear() {
return new Object[][] { 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, 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, 9, 9 + YDIFF_MEIJI, true},
{-1, JapaneseEra.MEIJI, 10, 10 + YDIFF_MEIJI, false}, {-1, JapaneseEra.MEIJI, 10, 10 + YDIFF_MEIJI, false},
@ -548,6 +553,7 @@ public class TCKJapaneseChronology {
{ JapaneseEra.TAISHO, 0, "Taisho"}, { JapaneseEra.TAISHO, 0, "Taisho"},
{ JapaneseEra.SHOWA, 1, "Showa"}, { JapaneseEra.SHOWA, 1, "Showa"},
{ JapaneseEra.HEISEI, 2, "Heisei"}, { JapaneseEra.HEISEI, 2, "Heisei"},
{ JapaneseEra.of(3), 3, "NewEra"}, // NEWERA
}; };
} }
@ -562,7 +568,7 @@ public class TCKJapaneseChronology {
@Test @Test
public void test_Japanese_badEras() { 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) { for (int badEra : badEras) {
try { try {
Era era = JapaneseChronology.INSTANCE.eraOf(badEra); Era era = JapaneseChronology.INSTANCE.eraOf(badEra);
@ -683,6 +689,7 @@ public class TCKJapaneseChronology {
{JapaneseChronology.INSTANCE.date(1989, 1, 7), "Japanese Showa 64-01-07"}, {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(1989, 1, 8), "Japanese Heisei 1-01-08"},
{JapaneseChronology.INSTANCE.date(2012, 12, 6), "Japanese Heisei 24-12-06"}, {JapaneseChronology.INSTANCE.date(2012, 12, 6), "Japanese Heisei 24-12-06"},
{JapaneseChronology.INSTANCE.date(2020, 1, 6), "Japanese NewEra 2-01-06"},
}; };
} }

View file

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -79,6 +79,7 @@ public class TCKJapaneseEra {
@DataProvider(name = "JapaneseEras") @DataProvider(name = "JapaneseEras")
Object[][] data_of_eras() { Object[][] data_of_eras() {
return new Object[][] { return new Object[][] {
{JapaneseEra.of(3), "NewEra", 3}, // NEWERA
{JapaneseEra.HEISEI, "Heisei", 2}, {JapaneseEra.HEISEI, "Heisei", 2},
{JapaneseEra.SHOWA, "Showa", 1}, {JapaneseEra.SHOWA, "Showa", 1},
{JapaneseEra.TAISHO, "Taisho", 0}, {JapaneseEra.TAISHO, "Taisho", 0},
@ -91,7 +92,7 @@ public class TCKJapaneseEra {
return new Object[][] { return new Object[][] {
{-2}, {-2},
{-3}, {-3},
{3}, {4},
{Integer.MIN_VALUE}, {Integer.MIN_VALUE},
{Integer.MAX_VALUE}, {Integer.MAX_VALUE},
}; };

View file

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -58,6 +58,8 @@ public class TestJapaneseChronology {
{ JapaneseEra.SHOWA, 1, 12, 25, 1926 }, { JapaneseEra.SHOWA, 1, 12, 25, 1926 },
{ JapaneseEra.SHOWA, 64, 1, 7, 1989 }, { JapaneseEra.SHOWA, 64, 1, 7, 1989 },
{ JapaneseEra.HEISEI, 1, 1, 8, 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 @@ public class TestJapaneseChronology {
{ JapaneseEra.SHOWA, 64, 7, 1, 7 }, { JapaneseEra.SHOWA, 64, 7, 1, 7 },
{ JapaneseEra.HEISEI, 1, 1, 1, 8 }, { JapaneseEra.HEISEI, 1, 1, 1, 8 },
{ JapaneseEra.HEISEI, 2, 8, 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 @@ public class TestJapaneseChronology {
Object[][] rangeData() { Object[][] rangeData() {
return new Object[][] { return new Object[][] {
// field, minSmallest, minLargest, maxSmallest, maxLargest // field, minSmallest, minLargest, maxSmallest, maxLargest
{ ChronoField.ERA, -1, -1, 2, 2}, { ChronoField.ERA, -1, -1, 3, 3},
{ ChronoField.YEAR_OF_ERA, 1, 1, 15, 999999999-1989 }, // depends on the current era { ChronoField.YEAR_OF_ERA, 1, 1, 15, 999999999-2019}, // depends on the current era
{ ChronoField.DAY_OF_YEAR, 1, 1, 7, 366}, { ChronoField.DAY_OF_YEAR, 1, 1, 7, 366},
{ ChronoField.YEAR, 1873, 1873, 999999999, 999999999}, { ChronoField.YEAR, 1873, 1873, 999999999, 999999999},
}; };
@ -105,7 +109,9 @@ public class TestJapaneseChronology {
{ JapaneseEra.SHOWA, 65, 1, 1 }, { JapaneseEra.SHOWA, 65, 1, 1 },
{ JapaneseEra.HEISEI, 1, 1, 7 }, { JapaneseEra.HEISEI, 1, 1, 7 },
{ JapaneseEra.HEISEI, 1, 2, 29 }, { 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 @@ public class TestJapaneseChronology {
{ JapaneseEra.SHOWA, 65 }, { JapaneseEra.SHOWA, 65 },
{ JapaneseEra.HEISEI, -1 }, { JapaneseEra.HEISEI, -1 },
{ JapaneseEra.HEISEI, 0 }, { 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 @@ public class TestJapaneseChronology {
{ JapaneseEra.SHOWA, 64, 8 }, { JapaneseEra.SHOWA, 64, 8 },
{ JapaneseEra.HEISEI, 1, 360 }, { JapaneseEra.HEISEI, 1, 360 },
{ JapaneseEra.HEISEI, 2, 366 }, { JapaneseEra.HEISEI, 2, 366 },
{ JapaneseEra.HEISEI, 31, 121 },
{ JapaneseEra.of(3), 1, 246 }, // NEWERA
{ JapaneseEra.of(3), 2, 367 }, // NEWERA
}; };
} }

View file

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -775,8 +775,10 @@ public class TestUmmAlQuraChronology {
{HijrahDate.of(1350,5,15), "Japanese Showa 6-09-28"}, {HijrahDate.of(1350,5,15), "Japanese Showa 6-09-28"},
{HijrahDate.of(1434,5,1), "Japanese Heisei 25-03-13"}, {HijrahDate.of(1434,5,1), "Japanese Heisei 25-03-13"},
{HijrahDate.of(1436,1,1), "Japanese Heisei 26-10-25"}, {HijrahDate.of(1436,1,1), "Japanese Heisei 26-10-25"},
{HijrahDate.of(1500,6,12), "Japanese Heisei 89-05-05"}, {HijrahDate.of(1440,8,25), "Japanese Heisei 31-04-30"},
{HijrahDate.of(1550,3,11), "Japanese Heisei 137-08-11"}, {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"},
}; };
} }

View file

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -46,7 +46,7 @@ public class Bug8007038 {
private static final int[][] eraMinMax = { private static final int[][] eraMinMax = {
{GregorianCalendar.BC, GregorianCalendar.AD}, {GregorianCalendar.BC, GregorianCalendar.AD},
{0, 1}, {0, 1},
{0, 4}, {0, 5},
{0, 1}, {0, 1},
{0, 1}, {0, 1},
{0, 1}, {0, 1},

View file

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -27,6 +27,7 @@
* @summary Unit test for Calendar.Builder. * @summary Unit test for Calendar.Builder.
*/ */
import java.time.LocalDateTime;
import java.util.*; import java.util.*;
import static java.util.Calendar.*; import static java.util.Calendar.*;
@ -132,7 +133,11 @@ public class BuilderTest {
.setFields(YEAR, 1, DAY_OF_YEAR, 1).build(); .setFields(YEAR, 1, DAY_OF_YEAR, 1).build();
expected = Calendar.getInstance(jaJPJP); expected = Calendar.getInstance(jaJPJP);
expected.clear(); 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); check(cal, expected);
// setLocale // setLocale
calb = builder(); calb = builder();

View file

@ -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);
}
}

View file

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -21,6 +21,7 @@
* questions. * questions.
*/ */
import java.time.LocalDateTime;
import java.util.*; import java.util.*;
import static java.util.GregorianCalendar.*; import static java.util.GregorianCalendar.*;
@ -49,7 +50,9 @@ public class NarrowNamesTest {
HOUR_OF_DAY, 10); HOUR_OF_DAY, 10);
test(US, AM_PM, "p", test(US, AM_PM, "p",
HOUR_OF_DAY, 23); 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); YEAR, 24, MONTH, DECEMBER, DAY_OF_MONTH, 23);
test(THTH, MONTH, NARROW_STANDALONE, "\u0e18.\u0e04.", test(THTH, MONTH, NARROW_STANDALONE, "\u0e18.\u0e04.",
YEAR, 2555, MONTH, DECEMBER, DAY_OF_MONTH, 5); YEAR, 2555, MONTH, DECEMBER, DAY_OF_MONTH, 5);

View file

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -50,8 +50,8 @@ import java.util.TimeZone;
public class SupplementalJapaneseEraTest { public class SupplementalJapaneseEraTest {
private static final Locale WAREKI_LOCALE = Locale.forLanguageTag("ja-JP-u-ca-japanese"); 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 SUP_ERA_NAME = "SupEra";
private static final String NEW_ERA_ABBR = "N.E."; private static final String SUP_ERA_ABBR = "S.E.";
private static int errors = 0; private static int errors = 0;
public static void main(String[] args) { public static void main(String[] args) {
@ -62,6 +62,7 @@ public class SupplementalJapaneseEraTest {
Calendar cal = new Calendar.Builder() Calendar cal = new Calendar.Builder()
.setCalendarType("japanese") .setCalendarType("japanese")
.setTimeZone(TimeZone.getTimeZone("GMT")) .setTimeZone(TimeZone.getTimeZone("GMT"))
.setFields(ERA, 5)
.setDate(200, FEBRUARY, 11) .setDate(200, FEBRUARY, 11)
.build(); .build();
System.out.println(cal.getTimeInMillis()); System.out.println(cal.getTimeInMillis());
@ -95,10 +96,9 @@ public class SupplementalJapaneseEraTest {
private static void testProperty() { private static void testProperty() {
Calendar jcal = new Calendar.Builder() Calendar jcal = new Calendar.Builder()
.setCalendarType("japanese") .setCalendarType("japanese")
.setFields(YEAR, 1, DAY_OF_YEAR, 1) .setFields(ERA, 6, YEAR, 1, DAY_OF_YEAR, 1)
.build(); .build();
Date firstDayOfEra = jcal.getTime(); Date firstDayOfEra = jcal.getTime();
jcal.set(ERA, jcal.get(ERA) - 1); // previous era jcal.set(ERA, jcal.get(ERA) - 1); // previous era
jcal.set(YEAR, 1); jcal.set(YEAR, 1);
jcal.set(DAY_OF_YEAR, 1); jcal.set(DAY_OF_YEAR, 1);
@ -113,7 +113,7 @@ public class SupplementalJapaneseEraTest {
// test long era name // test long era name
sdf = new SimpleDateFormat("GGGG y-MM-dd", WAREKI_LOCALE); sdf = new SimpleDateFormat("GGGG y-MM-dd", WAREKI_LOCALE);
got = sdf.format(firstDayOfEra); got = sdf.format(firstDayOfEra);
expected = NEW_ERA_NAME + " 1-02-11"; expected = SUP_ERA_NAME + " 1-02-11";
if (!expected.equals(got)) { if (!expected.equals(got)) {
System.err.printf("GGGG y-MM-dd: got=\"%s\", expected=\"%s\"%n", got, expected); System.err.printf("GGGG y-MM-dd: got=\"%s\", expected=\"%s\"%n", got, expected);
errors++; errors++;
@ -122,7 +122,7 @@ public class SupplementalJapaneseEraTest {
// test era abbreviation // test era abbreviation
sdf = new SimpleDateFormat("G y-MM-dd", WAREKI_LOCALE); sdf = new SimpleDateFormat("G y-MM-dd", WAREKI_LOCALE);
got = sdf.format(firstDayOfEra); got = sdf.format(firstDayOfEra);
expected = NEW_ERA_ABBR+" 1-02-11"; expected = SUP_ERA_ABBR + " 1-02-11";
if (!expected.equals(got)) { if (!expected.equals(got)) {
System.err.printf("G y-MM-dd: got=\"%s\", expected=\"%s\"%n", got, expected); System.err.printf("G y-MM-dd: got=\"%s\", expected=\"%s\"%n", got, expected);
errors++; errors++;
@ -139,30 +139,30 @@ public class SupplementalJapaneseEraTest {
// test java.time.chrono.JapaneseEra // test java.time.chrono.JapaneseEra
JapaneseDate jdate = JapaneseDate.of(year, 2, 11); JapaneseDate jdate = JapaneseDate.of(year, 2, 11);
got = jdate.toString(); got = jdate.toString();
expected = "Japanese " + NEW_ERA_NAME + " 1-02-11"; expected = "Japanese " + SUP_ERA_NAME + " 1-02-11";
if (!expected.equals(got)) { if (!expected.equals(got)) {
System.err.printf("JapaneseDate: got=\"%s\", expected=\"%s\"%n", got, expected); System.err.printf("JapaneseDate: got=\"%s\", expected=\"%s\"%n", got, expected);
errors++; errors++;
} }
JapaneseEra jera = jdate.getEra(); JapaneseEra jera = jdate.getEra();
got = jera.getDisplayName(TextStyle.FULL, Locale.US); got = jera.getDisplayName(TextStyle.FULL, Locale.US);
if (!NEW_ERA_NAME.equals(got)) { if (!SUP_ERA_NAME.equals(got)) {
System.err.printf("JapaneseEra (FULL): got=\"%s\", expected=\"%s\"%n", got, NEW_ERA_NAME); System.err.printf("JapaneseEra (FULL): got=\"%s\", expected=\"%s\"%n", got, SUP_ERA_NAME);
errors++; errors++;
} }
got = jera.getDisplayName(TextStyle.SHORT, Locale.US); got = jera.getDisplayName(TextStyle.SHORT, Locale.US);
if (!NEW_ERA_NAME.equals(got)) { if (!SUP_ERA_NAME.equals(got)) {
System.err.printf("JapaneseEra (SHORT): got=\"%s\", expected=\"%s\"%n", got, NEW_ERA_NAME); System.err.printf("JapaneseEra (SHORT): got=\"%s\", expected=\"%s\"%n", got, SUP_ERA_NAME);
errors++; errors++;
} }
got = jera.getDisplayName(TextStyle.NARROW, Locale.US); got = jera.getDisplayName(TextStyle.NARROW, Locale.US);
if (!NEW_ERA_ABBR.equals(got)) { if (!SUP_ERA_ABBR.equals(got)) {
System.err.printf("JapaneseEra (NARROW): got=\"%s\", expected=\"%s\"%n", got, NEW_ERA_ABBR); System.err.printf("JapaneseEra (NARROW): got=\"%s\", expected=\"%s\"%n", got, SUP_ERA_ABBR);
errors++; errors++;
} }
got = jera.getDisplayName(TextStyle.NARROW_STANDALONE, Locale.US); got = jera.getDisplayName(TextStyle.NARROW_STANDALONE, Locale.US);
if (!NEW_ERA_ABBR.equals(got)) { if (!SUP_ERA_ABBR.equals(got)) {
System.err.printf("JapaneseEra (NARROW_STANDALONE): got=\"%s\", expected=\"%s\"%n", got, NEW_ERA_ABBR); System.err.printf("JapaneseEra (NARROW_STANDALONE): got=\"%s\", expected=\"%s\"%n", got, SUP_ERA_ABBR);
errors++; errors++;
} }
@ -172,7 +172,7 @@ public class SupplementalJapaneseEraTest {
.withLocale(Locale.US) .withLocale(Locale.US)
.withChronology(JapaneseChronology.INSTANCE) .withChronology(JapaneseChronology.INSTANCE)
.format(jdate); .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)) { if (!expected.equals(got)) {
System.err.printf("java.time formatter full/short/narrow names: got=\"%s\", expected=\"%s\"%n", got, expected); System.err.printf("java.time formatter full/short/narrow names: got=\"%s\", expected=\"%s\"%n", got, expected);
errors++; errors++;

View file

@ -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. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
# #
# This code is free software; you can redistribute it and/or modify it # This code is free software; you can redistribute it and/or modify it
@ -34,8 +34,8 @@ STATUS=0
SINCE=`${TESTJAVA}/bin/java -cp "${TESTCLASSES}" SupplementalJapaneseEraTest -s` SINCE=`${TESTJAVA}/bin/java -cp "${TESTCLASSES}" SupplementalJapaneseEraTest -s`
echo "Tests with valid property values..." echo "Tests with valid property values..."
for P in "name=NewEra,abbr=N.E.,since=$SINCE" \ for P in "name=SupEra,abbr=S.E.,since=$SINCE" \
"name = NewEra, abbr = N.E., since = $SINCE" "name = SupEra, abbr = S.E., since = $SINCE"
do do
if ${TESTJAVA}/bin/java ${TESTVMOPTS} -cp "${TESTCLASSES}" \ if ${TESTJAVA}/bin/java ${TESTVMOPTS} -cp "${TESTCLASSES}" \
-D$PROPERTY="$P" SupplementalJapaneseEraTest -t; then -D$PROPERTY="$P" SupplementalJapaneseEraTest -t; then
@ -51,17 +51,17 @@ done
ERA=`${TESTJAVA}/bin/java -cp "${TESTCLASSES}" SupplementalJapaneseEraTest -e` ERA=`${TESTJAVA}/bin/java -cp "${TESTCLASSES}" SupplementalJapaneseEraTest -e`
echo "Tests with invalid property values..." echo "Tests with invalid property values..."
for P in "foo=Bar,name=NewEra,abbr=N.E.,since=$SINCE" \ for P in "foo=Bar,name=SupEra,abbr=S.E.,since=$SINCE" \
"=NewEra,abbr=N.E.,since=$SINCE" \ "=SupEra,abbr=S.E.,since=$SINCE" \
"=,abbr=N.E.,since=$SINCE" \ "=,abbr=S.E.,since=$SINCE" \
"name,abbr=N.E.,since=$SINCE" \ "name,abbr=S.E.,since=$SINCE" \
"abbr=N.E.,since=$SINCE" \ "abbr=S.E.,since=$SINCE" \
"name=NewEra,since=$SINCE" \ "name=SupEra,since=$SINCE" \
"name=,abbr=N.E.,since=$SINCE" \ "name=,abbr=S.E.,since=$SINCE" \
"name=NewEra,abbr=,since=$SINCE" \ "name=SupEra,abbr=,since=$SINCE" \
"name=NewEra,abbr=N.E." \ "name=SupEra,abbr=S.E." \
"name=NewEra,abbr=N.E.,since=0" \ "name=SupEra,abbr=S.E.,since=0" \
"name=NewEra,abbr=N.E.,since=9223372036854775808" # Long.MAX_VALUE+1 "name=SupEra,abbr=S.E.,since=9223372036854775808" # Long.MAX_VALUE+1
do do
if ${TESTJAVA}/bin/java ${TESTVMOPTS} -cp "${TESTCLASSES}" \ if ${TESTJAVA}/bin/java ${TESTVMOPTS} -cp "${TESTCLASSES}" \
-D$PROPERTY="$P" SupplementalJapaneseEraTest -b "$ERA"; then -D$PROPERTY="$P" SupplementalJapaneseEraTest -b "$ERA"; then

View file

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -192,6 +192,7 @@ public class ZoneOffsets {
cal2.setTimeZone(tz2); cal2.setTimeZone(tz2);
cal2.clear(); cal2.clear();
cal2.set(2005, MARCH, 11); cal2.set(2005, MARCH, 11);
adjustJapaneseEra(cal2);
// test5: set only ZONE_OFFSET in non-lenient // test5: set only ZONE_OFFSET in non-lenient
cal2.set(ZONE_OFFSET, gmtOffset); cal2.set(ZONE_OFFSET, gmtOffset);
if (t1 != cal2.getTime().getTime() || dst != cal2.get(DST_OFFSET)) { if (t1 != cal2.getTime().getTime() || dst != cal2.get(DST_OFFSET)) {
@ -201,6 +202,7 @@ public class ZoneOffsets {
cal2.setTimeZone(tz3); cal2.setTimeZone(tz3);
cal2.clear(); cal2.clear();
cal2.set(2005, MARCH, 11); cal2.set(2005, MARCH, 11);
adjustJapaneseEra(cal2);
// test6: set only DST_OFFSET in non-lenient // test6: set only DST_OFFSET in non-lenient
cal2.set(DST_OFFSET, dstOffset); cal2.set(DST_OFFSET, dstOffset);
if (t1 != cal2.getTime().getTime() || gmt != cal2.get(ZONE_OFFSET)) { if (t1 != cal2.getTime().getTime() || gmt != cal2.get(ZONE_OFFSET)) {
@ -210,6 +212,7 @@ public class ZoneOffsets {
cal2.setTimeZone(tz2); cal2.setTimeZone(tz2);
cal2.clear(); cal2.clear();
cal2.set(2005, MARCH, 11); cal2.set(2005, MARCH, 11);
adjustJapaneseEra(cal2);
// test7: set both ZONE_OFFSET and DST_OFFSET in non-lenient // test7: set both ZONE_OFFSET and DST_OFFSET in non-lenient
cal2.set(ZONE_OFFSET, gmtOffset); cal2.set(ZONE_OFFSET, gmtOffset);
cal2.set(DST_OFFSET, dstOffset); cal2.set(DST_OFFSET, dstOffset);
@ -220,6 +223,7 @@ public class ZoneOffsets {
cal2.setTimeZone(tz3); cal2.setTimeZone(tz3);
cal2.clear(); cal2.clear();
cal2.set(2005, MARCH, 11); cal2.set(2005, MARCH, 11);
adjustJapaneseEra(cal2);
// test8: set both ZONE_OFFSET and DST_OFFSET in non-lenient // test8: set both ZONE_OFFSET and DST_OFFSET in non-lenient
cal2.set(ZONE_OFFSET, gmtOffset); cal2.set(ZONE_OFFSET, gmtOffset);
cal2.set(DST_OFFSET, dstOffset); cal2.set(DST_OFFSET, dstOffset);
@ -234,4 +238,16 @@ public class ZoneOffsets {
+ ", gmtOffset=" + gmtOffset + ", dstOffset=" + dstOffset + ", gmtOffset=" + gmtOffset + ", dstOffset=" + dstOffset
+ ", cal1 time=" + t1 + ", cal2 time=" + cal2.getTime().getTime()); + ", 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;
}
} }