< prev index next >

src/java.base/share/classes/java/text/SimpleDateFormat.java

Print this page
rev 53363 : imported patch 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

@@ -1187,11 +1187,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];

@@ -2031,11 +2031,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 +2447,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 ? 0x8000 : 0), locale);
+        // Get LONG styles
+        Map<String, Integer> m = calendar.getDisplayNames(field,
+            Calendar.LONG_FORMAT | (forceStandaloneForm ? 0x8000 : 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 >