-
Bug
-
Resolution: Not an Issue
-
P2
-
None
-
8
The spec for j.t.SimpeDateFormat says regarding month format the following:
"Letter M produces context-sensitive month names"
So, accepting of the following template to SimpleDateFormat instance should produces contex-sensitive month names:
"MMMM"
We can compare the result with the result of SimpleDateFormat.getDateFormatSymbols().getMonths() result, because the spec of the DateFormatSymbols.getMonths says:
"If the language requires different forms for formatting and stand-alone usages, this method returns month names in the formatting form."
However, the following minimized test shows that for number of locales this comparison will fail:
-----------------------------------------------------------------------------------------------------------------------------
public class Test {
public static void main(String[] args) {
minimizedTest();
}
public static void minimizedTest() {
for (Locale l : Locale.getAvailableLocales()) {
checkSimpleDateFormatForLocale(l);
}
}
private static final Date date = new Date(1234567890);
// Letter M produces context-sensitive month names.
private static final String monthTemplate = "MMMM";
private static void checkSimpleDateFormatForLocale(Locale locale) {
SimpleDateFormat sdf = new SimpleDateFormat(monthTemplate, locale);
// If the language requires different forms for formatting and stand-alone usages, this method returns month names in the formatting form.
String dateFormatSymbol = sdf.getDateFormatSymbols().getMonths()[0];
String result = sdf.format(date, new StringBuffer(), new FieldPosition(0)).toString();
if (!dateFormatSymbol.equals(result)) {
System.out.println("---------------------------------");
System.out.println("Locale: " + locale);
System.out.println("SimpleDateFormat.getDateFormatSymbols month: " + dateFormatSymbol);
System.out.println("SimpleDateFormat.format month: " + result);
}
}
}
-----------------------------------------------------------------------------------------------------------------------------
If the following locales will be available they will be in output:
hr_HR, it, uk, sk, fi_FI, cs, el, uk_UA, cs_CZ, pl_PL, ca_ES, hr, lt, ca, ru_RU, fi, ru, el_GR, it_CH, sk_SK, lt_LT, it_IT, pl
Tested with jdk8 and jdk8u20.
"Letter M produces context-sensitive month names"
So, accepting of the following template to SimpleDateFormat instance should produces contex-sensitive month names:
"MMMM"
We can compare the result with the result of SimpleDateFormat.getDateFormatSymbols().getMonths() result, because the spec of the DateFormatSymbols.getMonths says:
"If the language requires different forms for formatting and stand-alone usages, this method returns month names in the formatting form."
However, the following minimized test shows that for number of locales this comparison will fail:
-----------------------------------------------------------------------------------------------------------------------------
public class Test {
public static void main(String[] args) {
minimizedTest();
}
public static void minimizedTest() {
for (Locale l : Locale.getAvailableLocales()) {
checkSimpleDateFormatForLocale(l);
}
}
private static final Date date = new Date(1234567890);
// Letter M produces context-sensitive month names.
private static final String monthTemplate = "MMMM";
private static void checkSimpleDateFormatForLocale(Locale locale) {
SimpleDateFormat sdf = new SimpleDateFormat(monthTemplate, locale);
// If the language requires different forms for formatting and stand-alone usages, this method returns month names in the formatting form.
String dateFormatSymbol = sdf.getDateFormatSymbols().getMonths()[0];
String result = sdf.format(date, new StringBuffer(), new FieldPosition(0)).toString();
if (!dateFormatSymbol.equals(result)) {
System.out.println("---------------------------------");
System.out.println("Locale: " + locale);
System.out.println("SimpleDateFormat.getDateFormatSymbols month: " + dateFormatSymbol);
System.out.println("SimpleDateFormat.format month: " + result);
}
}
}
-----------------------------------------------------------------------------------------------------------------------------
If the following locales will be available they will be in output:
hr_HR, it, uk, sk, fi_FI, cs, el, uk_UA, cs_CZ, pl_PL, ca_ES, hr, lt, ca, ru_RU, fi, ru, el_GR, it_CH, sk_SK, lt_LT, it_IT, pl
Tested with jdk8 and jdk8u20.
- relates to
-
JDK-8055900 j.t.SimpleDateFormat spec needs to be clarified regarding month patterns
-
- Closed
-
-
JDK-8058195 SimpleDateFormat parse bug
-
- Closed
-