< prev index next >
src/java.base/share/classes/java/text/SimpleDateFormat.java
Print this page
rev 53363 : [mq]: 8216969
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 1996, 2018, 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.
*
* 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. Oracle designates this
@@ -531,10 +531,12 @@
private transient int defaultCenturyStartYear;
private static final int MILLIS_PER_MINUTE = 60 * 1000;
+ private static final int STANDALONE_MASK = 0x8000; // Calendar.STANDALONE_MASK
+
// For time zones that have no names, use strings GMT+minutes and
// GMT-minutes. For instance, in France the time zone is GMT+60.
private static final String GMT = "GMT";
/**
@@ -1187,11 +1189,11 @@
maxIntCount, buffer);
}
}
break;
- case PATTERN_MONTH: // 'M' (context seinsive)
+ case PATTERN_MONTH: // 'M' (context sensitive)
if (useDateFormatSymbols) {
String[] months;
if (count >= 4) {
months = formatData.getMonths();
current = months[value];
@@ -1201,11 +1203,11 @@
}
} else {
if (count < 3) {
current = null;
} else if (forceStandaloneForm) {
- current = calendar.getDisplayName(field, style | 0x8000, locale);
+ current = calendar.getDisplayName(field, style | STANDALONE_MASK, locale);
if (current == null) {
current = calendar.getDisplayName(field, style, locale);
}
}
}
@@ -1225,11 +1227,11 @@
months = formatData.getShortMonths();
current = months[value];
}
} else {
if (count >= 3) {
- current = calendar.getDisplayName(field, style | 0x8000, locale);
+ current = calendar.getDisplayName(field, style | STANDALONE_MASK, locale);
}
}
if (current == null) {
zeroPaddingNumber(value+1, count, maxIntCount, buffer);
}
@@ -2031,11 +2033,11 @@
if ((index = matchString(text, start, Calendar.MONTH,
formatData.getShortMonths(), calb)) > 0) {
return index;
}
} else {
- Map<String, Integer> map = getDisplayNamesMap(field, locale);
+ Map<String, Integer> map = getDisplayContextNamesMap(field, locale);
if ((index = matchString(text, start, field, map, calb)) > 0) {
return index;
}
}
break parsing;
@@ -2447,10 +2449,23 @@
}
}
return map;
}
+ // for 'M' pattern only
+ private Map<String, Integer> getDisplayContextNamesMap(int field, Locale locale) {
+ Map<String, Integer> map = calendar.getDisplayNames(field,
+ Calendar.SHORT_FORMAT | (forceStandaloneForm ? STANDALONE_MASK : 0), locale);
+ // Get LONG styles
+ Map<String, Integer> m = calendar.getDisplayNames(field,
+ Calendar.LONG_FORMAT | (forceStandaloneForm ? STANDALONE_MASK : 0), locale);
+ if (m != null) {
+ map.putAll(m);
+ }
+ return map;
+ }
+
/**
* After reading an object from the input stream, the format
* pattern in the object is verified.
*
* @exception InvalidObjectException if the pattern is invalid
< prev index next >