提交 fa84c4e6 编写于 作者: R rpatil

8202088: Japanese new era implementation

8207152: Placeholder for Japanese new era should be two characters
8211398: Square character support for the Japanese new era
8180469: Wrong short form text for supplemental Japanese era
8206120: Add test cases for lenient Japanese era parsing
8218915: Change isJavaIdentifierStart and isJavaIdentifierPart to handle new code points
8217710: Add 5 currency code points to Java SE 8uX
Reviewed-by: coffeys, naoto
Contributed-by: deepak.kejriwal@oracle.com
上级 6cc3f9d3
/* /*
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * 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
...@@ -105,11 +105,21 @@ class CharacterData00 extends CharacterData { ...@@ -105,11 +105,21 @@ class CharacterData00 extends CharacterData {
} }
boolean isJavaIdentifierStart(int ch) { boolean isJavaIdentifierStart(int ch) {
// isJavaIdentifierStart strictly conforms to code points assigned
// in Unicode 6.2. Since code points {32FF} and {20BB..20BF} are not
// from Unicode 6.2, return false.
if(ch == 0x32FF || (ch>= 0x20BB && ch<= 0x20BF))
return false;
int props = getProperties(ch); int props = getProperties(ch);
return ((props & $$maskIdentifierInfo) >= $$lowJavaStart); return ((props & $$maskIdentifierInfo) >= $$lowJavaStart);
} }
boolean isJavaIdentifierPart(int ch) { boolean isJavaIdentifierPart(int ch) {
// isJavaIdentifierPart strictly conforms to code points assigned
// in Unicode 6.2. Since code points {32FF} and {20BB..20BF} are not
// from Unicode 6.2, return false.
if(ch == 0x32FF || (ch>= 0x20BB && ch<= 0x20BF))
return false;
int props = getProperties(ch); int props = getProperties(ch);
return ((props & $$nonzeroJavaPart) != 0); return ((props & $$nonzeroJavaPart) != 0);
} }
......
...@@ -7191,6 +7191,11 @@ ...@@ -7191,6 +7191,11 @@
20B8;TENGE SIGN;Sc;0;ET;;;;;N;;;;; 20B8;TENGE SIGN;Sc;0;ET;;;;;N;;;;;
20B9;INDIAN RUPEE SIGN;Sc;0;ET;;;;;N;;;;; 20B9;INDIAN RUPEE SIGN;Sc;0;ET;;;;;N;;;;;
20BA;TURKISH LIRA SIGN;Sc;0;ET;;;;;N;;;;; 20BA;TURKISH LIRA SIGN;Sc;0;ET;;;;;N;;;;;
20BB;NORDIC MARK SIGN;Sc;0;ET;;;;;N;;;;;
20BC;MANAT SIGN;Sc;0;ET;;;;;N;;;;;
20BD;RUBLE SIGN;Sc;0;ET;;;;;N;;;;;
20BE;LARI SIGN;Sc;0;ET;;;;;N;;;;;
20BF;BITCOIN SIGN;Sc;0;ET;;;;;N;;;;;
20D0;COMBINING LEFT HARPOON ABOVE;Mn;230;NSM;;;;;N;NON-SPACING LEFT HARPOON ABOVE;;;; 20D0;COMBINING LEFT HARPOON ABOVE;Mn;230;NSM;;;;;N;NON-SPACING LEFT HARPOON ABOVE;;;;
20D1;COMBINING RIGHT HARPOON ABOVE;Mn;230;NSM;;;;;N;NON-SPACING RIGHT HARPOON ABOVE;;;; 20D1;COMBINING RIGHT HARPOON ABOVE;Mn;230;NSM;;;;;N;NON-SPACING RIGHT HARPOON ABOVE;;;;
20D2;COMBINING LONG VERTICAL LINE OVERLAY;Mn;1;NSM;;;;;N;NON-SPACING LONG VERTICAL BAR OVERLAY;;;; 20D2;COMBINING LONG VERTICAL LINE OVERLAY;Mn;1;NSM;;;;;N;NON-SPACING LONG VERTICAL BAR OVERLAY;;;;
...@@ -11403,6 +11408,7 @@ ...@@ -11403,6 +11408,7 @@
32FC;CIRCLED KATAKANA WI;So;0;L;<circle> 30F0;;;;N;;;;; 32FC;CIRCLED KATAKANA WI;So;0;L;<circle> 30F0;;;;N;;;;;
32FD;CIRCLED KATAKANA WE;So;0;L;<circle> 30F1;;;;N;;;;; 32FD;CIRCLED KATAKANA WE;So;0;L;<circle> 30F1;;;;N;;;;;
32FE;CIRCLED KATAKANA WO;So;0;L;<circle> 30F2;;;;N;;;;; 32FE;CIRCLED KATAKANA WO;So;0;L;<circle> 30F2;;;;N;;;;;
32FF;SQUARE ERA NAME NEWERA;So;0;L;<square> 5143 53F7;;;;N;SQUARED TWO IDEOGRAPHS ERA NAME NEWERA;;;;
3300;SQUARE APAATO;So;0;L;<square> 30A2 30D1 30FC 30C8;;;;N;SQUARED APAATO;;;; 3300;SQUARE APAATO;So;0;L;<square> 30A2 30D1 30FC 30C8;;;;N;SQUARED APAATO;;;;
3301;SQUARE ARUHUA;So;0;L;<square> 30A2 30EB 30D5 30A1;;;;N;SQUARED ARUHUA;;;; 3301;SQUARE ARUHUA;So;0;L;<square> 30A2 30EB 30D5 30A1;;;;N;SQUARED ARUHUA;;;;
3302;SQUARE ANPEA;So;0;L;<square> 30A2 30F3 30DA 30A2;;;;N;SQUARED ANPEA;;;; 3302;SQUARE ANPEA;So;0;L;<square> 30A2 30F3 30DA 30A2;;;;N;SQUARED ANPEA;;;;
...@@ -3928,7 +3928,9 @@ class Character implements java.io.Serializable, Comparable<Character> { ...@@ -3928,7 +3928,9 @@ class Character implements java.io.Serializable, Comparable<Character> {
0x3220, // 3220..325F; COMMON 0x3220, // 3220..325F; COMMON
0x3260, // 3260..327E; HANGUL 0x3260, // 3260..327E; HANGUL
0x327F, // 327F..32CF; COMMON 0x327F, // 327F..32CF; COMMON
0x32D0, // 32D0..3357; KATAKANA 0x32D0, // 32D0..32FE; KATAKANA
0x32FF, // 32FF ; COMMON
0x3300, // 3300..3357; KATAKANA
0x3358, // 3358..33FF; COMMON 0x3358, // 3358..33FF; COMMON
0x3400, // 3400..4DBF; HAN 0x3400, // 3400..4DBF; HAN
0x4DC0, // 4DC0..4DFF; COMMON 0x4DC0, // 4DC0..4DFF; COMMON
...@@ -4249,7 +4251,9 @@ class Character implements java.io.Serializable, Comparable<Character> { ...@@ -4249,7 +4251,9 @@ class Character implements java.io.Serializable, Comparable<Character> {
COMMON, COMMON,
HANGUL, HANGUL,
COMMON, COMMON,
KATAKANA, KATAKANA, // 32D0..32FE
COMMON, // 32FF
KATAKANA, // 3300..3357
COMMON, COMMON,
HAN, HAN,
COMMON, COMMON,
......
...@@ -150,10 +150,15 @@ public final class JapaneseEra ...@@ -150,10 +150,15 @@ public final class JapaneseEra
* 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.
...@@ -171,6 +176,7 @@ public final class JapaneseEra ...@@ -171,6 +176,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());
......
/* /*
* Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * 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; ...@@ -50,6 +50,7 @@ import sun.util.calendar.ZoneInfo;
* 2 Taisho 1912-07-30 midnight local time * 2 Taisho 1912-07-30 midnight local time
* 3 Showa 1926-12-25 midnight local time * 3 Showa 1926-12-25 midnight local time
* 4 Heisei 1989-01-08 midnight local time * 4 Heisei 1989-01-08 midnight local time
* 5 NewEra 2019-05-01 midnight local time
* ------------------------------------------------------ * ------------------------------------------------------
* </tt></pre> * </tt></pre>
* *
...@@ -101,6 +102,11 @@ class JapaneseImperialCalendar extends Calendar { ...@@ -101,6 +102,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)
private static final int EPOCH_YEAR = 1970; private static final int EPOCH_YEAR = 1970;
...@@ -133,6 +139,9 @@ class JapaneseImperialCalendar extends Calendar { ...@@ -133,6 +139,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
...@@ -228,13 +237,18 @@ class JapaneseImperialCalendar extends Calendar { ...@@ -228,13 +237,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;
...@@ -1713,12 +1727,12 @@ class JapaneseImperialCalendar extends Calendar { ...@@ -1713,12 +1727,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());
...@@ -1853,7 +1867,7 @@ class JapaneseImperialCalendar extends Calendar { ...@@ -1853,7 +1867,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)
...@@ -2337,7 +2351,7 @@ class JapaneseImperialCalendar extends Calendar { ...@@ -2337,7 +2351,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;
} }
/** /**
......
/* /*
* Copyright (c) 1996, 2014, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1996, 2019, 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 { ...@@ -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 { ...@@ -115,6 +116,7 @@ public class FormatData extends ParallelListResourceBundle {
"Taisho", "Taisho",
"Showa", "Showa",
"Heisei", "Heisei",
"NewEra", // NewEra
}; };
return new Object[][] { return new Object[][] {
......
/* /*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * 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
...@@ -237,6 +237,7 @@ public class JavaTimeSupplementary extends OpenListResourceBundle { ...@@ -237,6 +237,7 @@ public class JavaTimeSupplementary extends OpenListResourceBundle {
"Taisho", "Taisho",
"Showa", "Showa",
"Heisei", "Heisei",
"NewEra", // New Era
} }
}, },
{ "java.time.japanese.short.Eras", { "java.time.japanese.short.Eras",
...@@ -246,6 +247,7 @@ public class JavaTimeSupplementary extends OpenListResourceBundle { ...@@ -246,6 +247,7 @@ public class JavaTimeSupplementary extends OpenListResourceBundle {
"Taisho", "Taisho",
"Showa", "Showa",
"Heisei", "Heisei",
"NewEra", // New Era
} }
}, },
{ "java.time.roc.DatePatterns", { "java.time.roc.DatePatterns",
......
/* /*
* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1996, 2019, 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 { ...@@ -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
"\u5143\u53f7", // NewEra
}; };
final String[] rocEras = { final String[] rocEras = {
"\u6c11\u56fd\u524d", "\u6c11\u56fd\u524d",
......
/* /*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * 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
...@@ -198,6 +198,7 @@ public class JavaTimeSupplementary_ja extends OpenListResourceBundle { ...@@ -198,6 +198,7 @@ public class JavaTimeSupplementary_ja extends OpenListResourceBundle {
"\u5927\u6b63", "\u5927\u6b63",
"\u662d\u548c", "\u662d\u548c",
"\u5e73\u6210", "\u5e73\u6210",
"\u5143\u53f7", // NewEra
} }
}, },
{ "java.time.japanese.short.Eras", { "java.time.japanese.short.Eras",
...@@ -207,6 +208,7 @@ public class JavaTimeSupplementary_ja extends OpenListResourceBundle { ...@@ -207,6 +208,7 @@ public class JavaTimeSupplementary_ja extends OpenListResourceBundle {
"\u5927\u6b63", "\u5927\u6b63",
"\u662d\u548c", "\u662d\u548c",
"\u5e73\u6210", "\u5e73\u6210",
"\u5143\u53f7", // NewEra
} }
}, },
{ "java.time.long.Eras", { "java.time.long.Eras",
......
/* /*
* Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * 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
...@@ -49,6 +49,7 @@ import java.util.TimeZone; ...@@ -49,6 +49,7 @@ import java.util.TimeZone;
* Taisho 1912-07-30 midnight local time * Taisho 1912-07-30 midnight local time
* Showa 1926-12-26 midnight local time * Showa 1926-12-26 midnight local time
* Heisei 1989-01-08 midnight local time * Heisei 1989-01-08 midnight local time
* NewEra 2019-05-01 midnight local time
* Julian calendar BeforeCommonEra -292275055-05-16T16:47:04.192Z * Julian calendar BeforeCommonEra -292275055-05-16T16:47:04.192Z
* CommonEra 0000-12-30 midnight local time * CommonEra 0000-12-30 midnight local time
* Taiwanese calendar MinGuo 1911-01-01 midnight local time * Taiwanese calendar MinGuo 1911-01-01 midnight local time
......
/* /*
* Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * 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; ...@@ -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
...@@ -69,22 +69,43 @@ public class CalendarNameProviderImpl extends CalendarNameProvider implements Av ...@@ -69,22 +69,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) {
// 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 Era supEra = jeras[value - 1]; // 0-based index
return style == LONG ? if (javatime) {
return getBaseStyle(style) == NARROW_FORMAT ?
supEra.getAbbreviation() :
supEra.getName();
} else {
return (style & LONG) != 0 ?
supEra.getName() : supEra.getName() :
supEra.getAbbreviation(); supEra.getAbbreviation();
} }
} }
} else {
return null; return null;
}
} else {
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.
...@@ -158,7 +179,7 @@ public class CalendarNameProviderImpl extends CalendarNameProvider implements Av ...@@ -158,7 +179,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);
} }
...@@ -239,6 +260,11 @@ public class CalendarNameProviderImpl extends CalendarNameProvider implements Av ...@@ -239,6 +260,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);
...@@ -262,7 +288,7 @@ public class CalendarNameProviderImpl extends CalendarNameProvider implements Av ...@@ -262,7 +288,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.");
...@@ -314,7 +340,7 @@ public class CalendarNameProviderImpl extends CalendarNameProvider implements Av ...@@ -314,7 +340,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";
......
...@@ -29,12 +29,14 @@ ...@@ -29,12 +29,14 @@
# Taisho since 1912-07-30 00:00:00 local time (Gregorian) # Taisho since 1912-07-30 00:00:00 local time (Gregorian)
# Showa since 1926-12-25 00:00:00 local time (Gregorian) # Showa since 1926-12-25 00:00:00 local time (Gregorian)
# Heisei since 1989-01-08 00:00:00 local time (Gregorian) # Heisei since 1989-01-08 00:00:00 local time (Gregorian)
# NewEra since 2019-05-01 00:00:00 local time (Gregorian)
calendar.japanese.type: LocalGregorianCalendar calendar.japanese.type: LocalGregorianCalendar
calendar.japanese.eras: \ calendar.japanese.eras: \
name=Meiji,abbr=M,since=-3218832000000; \ name=Meiji,abbr=M,since=-3218832000000; \
name=Taisho,abbr=T,since=-1812153600000; \ name=Taisho,abbr=T,since=-1812153600000; \
name=Showa,abbr=S,since=-1357603200000; \ name=Showa,abbr=S,since=-1357603200000; \
name=Heisei,abbr=H,since=600220800000 name=Heisei,abbr=H,since=600220800000; \
name=NewEra,abbr=N,since=1556668800000
# #
# Taiwanese calendar # Taiwanese calendar
......
...@@ -147,6 +147,7 @@ ...@@ -147,6 +147,7 @@
208D ; Common # Ps SUBSCRIPT LEFT PARENTHESIS 208D ; Common # Ps SUBSCRIPT LEFT PARENTHESIS
208E ; Common # Pe SUBSCRIPT RIGHT PARENTHESIS 208E ; Common # Pe SUBSCRIPT RIGHT PARENTHESIS
20A0..20BA ; Common # Sc [27] EURO-CURRENCY SIGN..TURKISH LIRA SIGN 20A0..20BA ; Common # Sc [27] EURO-CURRENCY SIGN..TURKISH LIRA SIGN
20BB..20BF ; Common # Sc [5] NORDIC MARK SIGN..BITCOIN SIGN
2100..2101 ; Common # So [2] ACCOUNT OF..ADDRESSED TO THE SUBJECT 2100..2101 ; Common # So [2] ACCOUNT OF..ADDRESSED TO THE SUBJECT
2102 ; Common # L& DOUBLE-STRUCK CAPITAL C 2102 ; Common # L& DOUBLE-STRUCK CAPITAL C
2103..2106 ; Common # So [4] DEGREE CELSIUS..CADA UNA 2103..2106 ; Common # So [4] DEGREE CELSIUS..CADA UNA
...@@ -381,6 +382,7 @@ ...@@ -381,6 +382,7 @@
328A..32B0 ; Common # So [39] CIRCLED IDEOGRAPH MOON..CIRCLED IDEOGRAPH NIGHT 328A..32B0 ; Common # So [39] CIRCLED IDEOGRAPH MOON..CIRCLED IDEOGRAPH NIGHT
32B1..32BF ; Common # No [15] CIRCLED NUMBER THIRTY SIX..CIRCLED NUMBER FIFTY 32B1..32BF ; Common # No [15] CIRCLED NUMBER THIRTY SIX..CIRCLED NUMBER FIFTY
32C0..32CF ; Common # So [16] IDEOGRAPHIC TELEGRAPH SYMBOL FOR JANUARY..LIMITED LIABILITY SIGN 32C0..32CF ; Common # So [16] IDEOGRAPHIC TELEGRAPH SYMBOL FOR JANUARY..LIMITED LIABILITY SIGN
32FF ; Common # So SQUARE ERA NAME NEWERA
3358..33FF ; Common # So [168] IDEOGRAPHIC TELEGRAPH SYMBOL FOR HOUR ZERO..SQUARE GAL 3358..33FF ; Common # So [168] IDEOGRAPHIC TELEGRAPH SYMBOL FOR HOUR ZERO..SQUARE GAL
4DC0..4DFF ; Common # So [64] HEXAGRAM FOR THE CREATIVE HEAVEN..HEXAGRAM FOR BEFORE COMPLETION 4DC0..4DFF ; Common # So [64] HEXAGRAM FOR THE CREATIVE HEAVEN..HEXAGRAM FOR BEFORE COMPLETION
A700..A716 ; Common # Sk [23] MODIFIER LETTER CHINESE TONE YIN PING..MODIFIER LETTER EXTRA-LOW LEFT-STEM TONE BAR A700..A716 ; Common # Sk [23] MODIFIER LETTER CHINESE TONE YIN PING..MODIFIER LETTER EXTRA-LOW LEFT-STEM TONE BAR
......
/*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* 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
* @summary Test behavior of isJavaIdentifierXX, testIsJavaLetter, and
* testIsJavaLetterOrDigit methods for all code points.
* @bug 8218915
*/
import java.util.List;
import java.util.ArrayList;
public class TestIsJavaIdentifierMethods {
// List of new code points are not present in Unicode 6.2.
private static final List<Integer> UNASSIGNED_CODEPOINTS_IN_6_2
= new ArrayList<Integer>()
{{
add(0x20BB); // NORDIC MARK SIGN
add(0x20BC); // MANAT SIGN
add(0x20BD); // RUBLE SIGN
add(0x20BE); // LARI SIGN
add(0x20BF); // BITCOIN SIGN
add(0x32FF); // SQUARE ERA NAME NEWERA
}};
public static void main(String[] args) {
testIsJavaIdentifierPart_int();
testIsJavaIdentifierPart_char();
testIsJavaIdentifierStart_int();
testIsJavaIdentifierStart_char();
testIsJavaLetter();
testIsJavaLetterOrDigit();
}
/**
* Assertion testing for public static boolean isJavaIdentifierPart(int
* codePoint), A character may be part of a Java identifier if any of the
* following are true:
* <ul>
* <li>it is a letter</li>
* <li>it is a currency symbol (such as <code>'$'</code>)</li>
* <li>it is a connecting punctuation character (such as <code>'_'</code>)
* </li>
* <li>it is a digit</li>
* <li>it is a numeric letter (such as a Roman numeral character)</li>
* <li>it is a combining mark</li>
* <li>it is a non-spacing mark</li>
* <li><code>isIdentifierIgnorable</code> returns <code>true</code> for the
* character</li>
* </ul>
* All code points from (0x0000..0x10FFFF) are tested.
*/
public static void testIsJavaIdentifierPart_int() {
for (int cp = 0; cp <= Character.MAX_CODE_POINT; cp++) {
boolean expected = false;
// Since Character.isJavaIdentifierPart(int) strictly conforms to
// character information from version 6.2 of the Unicode Standard,
// check if code point is in "UNASSIGNED_CODEPOINTS_IN_6_2"
// list. If the code point is found in list
// "UNASSIGNED_CODEPOINTS_IN_6_2", value of variable
// "expected" is considered false.
if (!UNASSIGNED_CODEPOINTS_IN_6_2.contains(cp)) {
byte type = (byte) Character.getType(cp);
expected = Character.isLetter(cp)
|| type == Character.CURRENCY_SYMBOL
|| type == Character.CONNECTOR_PUNCTUATION
|| Character.isDigit(cp)
|| type == Character.LETTER_NUMBER
|| type == Character.COMBINING_SPACING_MARK
|| type == Character.NON_SPACING_MARK
|| Character.isIdentifierIgnorable(cp);
}
if (Character.isJavaIdentifierPart(cp) != expected) {
throw new RuntimeException(
"Character.isJavaIdentifierPart(int) failed for codepoint "
+ Integer.toHexString(cp));
}
}
}
/**
* Assertion testing for public static boolean isJavaIdentifierPart(char
* ch), A character may be part of a Java identifier if any of the
* following are true:
* <ul>
* <li>it is a letter;
* <li>it is a currency symbol (such as "$");
* <li>it is a connecting punctuation character (such as "_");
* <li>it is a digit;
* <li>it is a numeric letter (such as a Roman numeral character);
* <li>it is a combining mark;
* <li>it is a non-spacing mark;
* <li>isIdentifierIgnorable returns true for the character.
* </ul>
* All Unicode code points in the BMP (0x0000..0xFFFF) are tested.
*/
public static void testIsJavaIdentifierPart_char() {
for (int i = 0; i <= Character.MAX_VALUE; ++i) {
char ch = (char) i;
boolean expected = false;
// Since Character.isJavaIdentifierPart(char) strictly conforms to
// character information from version 6.2 of the Unicode Standard,
// check if code point is in "UNASSIGNED_CODEPOINTS_IN_6_2"
// list. If the code point is found in list
// "UNASSIGNED_CODEPOINTS_IN_6_2", value of variable
// "expected" is considered false.
if (!UNASSIGNED_CODEPOINTS_IN_6_2.contains(i)) {
byte type = (byte) Character.getType(ch);
expected = Character.isLetter(ch)
|| type == Character.CURRENCY_SYMBOL
|| type == Character.CONNECTOR_PUNCTUATION
|| Character.isDigit(ch)
|| type == Character.LETTER_NUMBER
|| type == Character.COMBINING_SPACING_MARK
|| type == Character.NON_SPACING_MARK
|| Character.isIdentifierIgnorable(ch);
}
if (Character.isJavaIdentifierPart((char) i) != expected) {
throw new RuntimeException(
"Character.isJavaIdentifierPart(char) failed for codepoint "
+ Integer.toHexString(i));
}
}
}
/**
* Assertion testing for public static boolean isJavaIdentifierStart(int
* codePoint), A character may start a Java identifier if and only if it is
* one of the following:
* <ul>
* <li>it is a letter;</li>
* <li>getType(ch) returns LETTER_NUMBER;</li>
* <li>it is a currency symbol (such as "$");</li>
* <li>it is a connecting punctuation character (such as "_");</li>
* </ul>
* All Code points from (0x0000..0x10FFFF) are tested.
*/
public static void testIsJavaIdentifierStart_int() {
for (int cp = 0; cp <= Character.MAX_CODE_POINT; cp++) {
boolean expected = false;
// Since Character.isJavaIdentifierStart(int) strictly conforms to
// character information from version 6.2 of the Unicode Standard,
// check if code point is in "UNASSIGNED_CODEPOINTS_IN_6_2"
// list. If the code point is found in list
// "UNASSIGNED_CODEPOINTS_IN_6_2", value of variable
// "expected" is considered false.
if (!UNASSIGNED_CODEPOINTS_IN_6_2.contains(cp)) {
byte type = (byte) Character.getType(cp);
expected = Character.isLetter(cp)
|| type == Character.LETTER_NUMBER
|| type == Character.CURRENCY_SYMBOL
|| type == Character.CONNECTOR_PUNCTUATION;
}
if (Character.isJavaIdentifierStart(cp) != expected) {
throw new RuntimeException(
"Character.isJavaIdentifierStart(int) failed for codepoint "
+ Integer.toHexString(cp));
}
}
}
/**
* Assertion testing for public static boolean isJavaIdentifierStart(char),
* A character may start a Java identifier if and only if it is
* one of the following:
* <ul>
* <li>it is a letter;</li>
* <li>getType(ch) returns LETTER_NUMBER;</li>
* <li>it is a currency symbol (such as "$");</li>
* <li>it is a connecting punctuation character (such as "_");</li>
* </ul>
* All Unicode code points in the BMP (0x0000..0xFFFF) are tested.
*/
public static void testIsJavaIdentifierStart_char() {
for (int i = 0; i <= Character.MAX_VALUE; i++) {
char ch = (char) i;
boolean expected = false;
// Since Character.isJavaIdentifierStart(char) strictly conforms to
// character information from version 6.2 of the Unicode Standard,
// check if code point is in "UNASSIGNED_CODEPOINTS_IN_6_2"
// list. If the code point is found in list
// "UNASSIGNED_CODEPOINTS_IN_6_2", value of variable
// "expected" is considered false.
if (!UNASSIGNED_CODEPOINTS_IN_6_2.contains(i)) {
byte type = (byte) Character.getType(ch);
expected = Character.isLetter(ch)
|| type == Character.LETTER_NUMBER
|| type == Character.CURRENCY_SYMBOL
|| type == Character.CONNECTOR_PUNCTUATION;
}
if (Character.isJavaIdentifierStart(ch) != expected) {
throw new RuntimeException(
"Character.isJavaIdentifierStart(char) failed for codepoint "
+ Integer.toHexString(i));
}
}
}
/**
* Assertion testing for public static boolean isJavaLetter(char ch), A
* character may start a Java identifier if and only if one of the
* following is true:
* <ul>
* <li>isLetter(ch) returns true
* <li>getType(ch) returns LETTER_NUMBER
* <li>ch is a currency symbol (such as "$")
* <li>ch is a connecting punctuation character (such as "_").
* </ul>
* All Unicode code points in the BMP (0x0000..0xFFFF) are tested.
*/
public static void testIsJavaLetter() {
for (int i = 0; i <= Character.MAX_VALUE; ++i) {
char ch = (char) i;
boolean expected = false;
// Since Character.isJavaLetter(char) strictly conforms to
// character information from version 6.2 of the Unicode Standard,
// check if code point is in "UNASSIGNED_CODEPOINTS_IN_6_2"
// list. If the code point is found in list
// "UNASSIGNED_CODEPOINTS_IN_6_2", value of variable
// "expected" is considered false.
if (!UNASSIGNED_CODEPOINTS_IN_6_2.contains(i)) {
byte type = (byte) Character.getType(ch);
expected = Character.isLetter(ch)
|| type == Character.LETTER_NUMBER
|| type == Character.CURRENCY_SYMBOL
|| type == Character.CONNECTOR_PUNCTUATION;
}
if (Character.isJavaLetter(ch) != expected) {
throw new RuntimeException(
"Character.isJavaLetter(ch) failed for codepoint "
+ Integer.toHexString(i));
}
}
}
/**
* Assertion testing for public static boolean isJavaLetterOrDigit(char
* ch), A character may be part of a Java identifier if and only if any
* of the following are true:
* <ul>
* <li>it is a letter
* <li>it is a currency symbol (such as '$')
* <li>it is a connecting punctuation character (such as '_')
* <li>it is a digit
* <li>it is a numeric letter (such as a Roman numeral character)
* <li>it is a combining mark
* <li>it is a non-spacing mark
* <li>isIdentifierIgnorable returns true for the character.
* </ul>
* All Unicode code points in the BMP (0x0000..0xFFFF) are tested.
*/
public static void testIsJavaLetterOrDigit() {
for (int i = 0; i <= Character.MAX_VALUE; ++i) {
char ch = (char) i;
boolean expected = false;
// Since Character.isJavaLetterOrDigit(char) strictly conforms to
// character information from version 6.2 of the Unicode Standard,
// check if code point is in "UNASSIGNED_CODEPOINTS_IN_6_2"
// list. If the code point is found in list
// "UNASSIGNED_CODEPOINTS_IN_6_2", value of variable
// "expected" is considered false.
if (!UNASSIGNED_CODEPOINTS_IN_6_2.contains(i)) {
byte type = (byte) Character.getType(ch);
expected = Character.isLetter(ch)
|| type == Character.CURRENCY_SYMBOL
|| type == Character.CONNECTOR_PUNCTUATION
|| Character.isDigit(ch)
|| type == Character.LETTER_NUMBER
|| type == Character.COMBINING_SPACING_MARK
|| type == Character.NON_SPACING_MARK
|| Character.isIdentifierIgnorable(ch);
}
if (Character.isJavaLetterOrDigit(ch) != expected) {
throw new RuntimeException(
"Character.isJavaLetterOrDigit(ch) failed for codepoint "
+ Integer.toHexString(i));
}
}
}
}
/* /*
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2010, 2019, 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 { ...@@ -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);
} }
} }
......
/* /*
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * 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; ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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"},
}; };
} }
......
/* /*
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * 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
...@@ -77,6 +77,7 @@ public class TCKJapaneseEra { ...@@ -77,6 +77,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},
......
/* /*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * 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 { ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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
}; };
} }
......
/* /*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * 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 { ...@@ -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"},
}; };
} }
......
/* /*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * 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
...@@ -20,6 +20,13 @@ ...@@ -20,6 +20,13 @@
* or visit www.oracle.com if you need additional information or have any * or visit www.oracle.com if you need additional information or have any
* questions. * questions.
*/ */
/*
*
* @test
* @bug 8206120
*/
package test.java.time.format; package test.java.time.format;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
...@@ -37,6 +44,7 @@ import java.time.format.DateTimeFormatter; ...@@ -37,6 +44,7 @@ import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder; import java.time.format.DateTimeFormatterBuilder;
import java.time.format.DateTimeParseException; import java.time.format.DateTimeParseException;
import java.time.format.FormatStyle; import java.time.format.FormatStyle;
import java.time.format.ResolverStyle;
import java.time.format.TextStyle; import java.time.format.TextStyle;
import java.time.temporal.TemporalAccessor; import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalQueries; import java.time.temporal.TemporalQueries;
...@@ -128,6 +136,16 @@ public class TestNonIsoFormatter { ...@@ -128,6 +136,16 @@ public class TestNonIsoFormatter {
}; };
} }
@DataProvider(name="lenient_eraYear")
Object[][] lenientEraYear() {
return new Object[][] {
// Chronology, lenient era/year, strict era/year
{ JAPANESE, "Meiji 123", "Heisei 2" },
{ JAPANESE, "Showa 65", "Heisei 2" },
{ JAPANESE, "Heisei 32", "NewEra 2" }, // NewEra
};
}
@Test(dataProvider="format_data") @Test(dataProvider="format_data")
public void test_formatLocalizedDate(Chronology chrono, Locale formatLocale, Locale numberingLocale, public void test_formatLocalizedDate(Chronology chrono, Locale formatLocale, Locale numberingLocale,
ChronoLocalDate date, String expected) { ChronoLocalDate date, String expected) {
...@@ -166,4 +184,15 @@ public class TestNonIsoFormatter { ...@@ -166,4 +184,15 @@ public class TestNonIsoFormatter {
Chronology cal = ta.query(TemporalQueries.chronology()); Chronology cal = ta.query(TemporalQueries.chronology());
assertEquals(cal, chrono); assertEquals(cal, chrono);
} }
@Test(dataProvider="lenient_eraYear")
public void test_lenientEraYear(Chronology chrono, String lenient, String strict) {
String mdStr = "-01-01";
DateTimeFormatter dtf = new DateTimeFormatterBuilder()
.appendPattern("GGGG y-M-d")
.toFormatter()
.withChronology(chrono);
DateTimeFormatter dtfLenient = dtf.withResolverStyle(ResolverStyle.LENIENT);
assertEquals(LocalDate.parse(lenient+mdStr, dtfLenient), LocalDate.parse(strict+mdStr, dtf));
}
} }
/* /*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * 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
...@@ -45,7 +45,7 @@ public class Bug8007038 { ...@@ -45,7 +45,7 @@ public class Bug8007038 {
private final static int[][] eraMinMax = { private final static 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},
......
/* /*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * 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 @@ ...@@ -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 { ...@@ -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();
if (LocalDateTime.now().isBefore(LocalDateTime.of(2019, 5, 1, 0, 0))) {
expected.set(1, JANUARY, 8); expected.set(1, JANUARY, 8);
} else {
expected.set(1, MAY, 1);
}
check(cal, expected); check(cal, expected);
// setLocale // setLocale
calb = builder(); calb = builder();
......
/*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* 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.
* @run testng/othervm JapaneseEraNameTest
* @run testng/othervm -Djava.locale.providers=CLDR,JRE 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, "\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);
}
}
/*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* 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 8206120
* @summary Test whether lenient era is accepted in JapaneseImperialCalendar
* @run testng/othervm JapaneseLenientEraTest
*/
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals;
@Test
public class JapaneseLenientEraTest {
@DataProvider(name="lenientEra")
Object[][] names() {
return new Object[][] {
// lenient era/year, strict era/year
{ "Meiji 123", "Heisei 2" },
{ "Showa 65", "Heisei 2" },
{ "Heisei 32", "NewEra 2" }, // NewEra
};
}
@Test(dataProvider="lenientEra")
public void testLenientEra(String lenient, String strict) throws Exception {
Calendar c = new Calendar.Builder()
.setCalendarType("japanese")
.build();
DateFormat df = new SimpleDateFormat("GGGG y-M-d", Locale.ROOT);
df.setCalendar(c);
Date lenDate = df.parse(lenient + "-01-01");
df.setLenient(false);
Date strDate = df.parse(strict + "-01-01");
assertEquals(lenDate, strDate);
}
}
/* /*
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * 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 @@ ...@@ -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.*;
...@@ -45,7 +46,9 @@ public class NarrowNamesTest { ...@@ -45,7 +46,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);
......
/* /*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2017, 2019, 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
...@@ -60,8 +60,8 @@ import static org.testng.Assert.*; ...@@ -60,8 +60,8 @@ import static org.testng.Assert.*;
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 final int NEW_ERA_YEAR = 200; private static final int NEW_ERA_YEAR = 200;
private static final int NEW_ERA_MONTH = FEBRUARY; private static final int NEW_ERA_MONTH = FEBRUARY;
private static final int NEW_ERA_DAY = 11; private static final int NEW_ERA_DAY = 11;
...@@ -96,7 +96,7 @@ public class SupplementalJapaneseEraTest { ...@@ -96,7 +96,7 @@ 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();
...@@ -114,7 +114,7 @@ public class SupplementalJapaneseEraTest { ...@@ -114,7 +114,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++;
...@@ -123,7 +123,7 @@ public class SupplementalJapaneseEraTest { ...@@ -123,7 +123,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++;
...@@ -140,30 +140,30 @@ public class SupplementalJapaneseEraTest { ...@@ -140,30 +140,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,10 +172,12 @@ public class SupplementalJapaneseEraTest { ...@@ -172,10 +172,12 @@ public class SupplementalJapaneseEraTest {
.appendPattern("GGGG") .appendPattern("GGGG")
.appendLiteral(" ") .appendLiteral(" ")
.appendPattern("G") .appendPattern("G")
.appendLiteral(" ")
.appendPattern("GGGGG")
.toFormatter(Locale.US) .toFormatter(Locale.US)
.withChronology(JapaneseChronology.INSTANCE) .withChronology(JapaneseChronology.INSTANCE)
.format(jdate); .format(jdate);
expected = 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 long/abbr names: got=\"%s\", expected=\"%s\"%n", got, expected); System.err.printf("java.time formatter long/abbr names: got=\"%s\", expected=\"%s\"%n", got, expected);
errors++; errors++;
...@@ -230,8 +232,8 @@ public class SupplementalJapaneseEraTest { ...@@ -230,8 +232,8 @@ public class SupplementalJapaneseEraTest {
if (eras != null) { if (eras != null) {
p.setProperty(JA_CAL_KEY, p.setProperty(JA_CAL_KEY,
eras + eras +
"; name=" + SupplementalJapaneseEraTest.NEW_ERA_NAME + "; name=" + SupplementalJapaneseEraTest.SUP_ERA_NAME +
",abbr=" + SupplementalJapaneseEraTest.NEW_ERA_ABBR + ",abbr=" + SupplementalJapaneseEraTest.SUP_ERA_ABBR +
",since=" + since()); ",since=" + since());
} }
try (BufferedWriter bw = Files.newBufferedWriter(dst)) { try (BufferedWriter bw = Files.newBufferedWriter(dst)) {
...@@ -243,6 +245,7 @@ public class SupplementalJapaneseEraTest { ...@@ -243,6 +245,7 @@ public class SupplementalJapaneseEraTest {
return new Calendar.Builder() return new Calendar.Builder()
.setCalendarType("japanese") .setCalendarType("japanese")
.setTimeZone(TimeZone.getTimeZone("GMT")) .setTimeZone(TimeZone.getTimeZone("GMT"))
.setFields(ERA, 5)
.setDate(SupplementalJapaneseEraTest.NEW_ERA_YEAR, .setDate(SupplementalJapaneseEraTest.NEW_ERA_YEAR,
SupplementalJapaneseEraTest.NEW_ERA_MONTH, SupplementalJapaneseEraTest.NEW_ERA_MONTH,
SupplementalJapaneseEraTest.NEW_ERA_DAY) SupplementalJapaneseEraTest.NEW_ERA_DAY)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册