You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by GitBox <gi...@apache.org> on 2022/05/14 21:42:34 UTC

[GitHub] [commons-lang] stevebosman-oc commented on a diff in pull request #892: LANG-1680 Add support for standalone month formats

stevebosman-oc commented on code in PR #892:
URL: https://github.com/apache/commons-lang/pull/892#discussion_r873077554


##########
src/main/java/org/apache/commons/lang3/time/DateUtils.java:
##########
@@ -1831,4 +1831,40 @@ public void remove() {
         }
     }
 
+    /**
+     * Obtain full standalone month names as used in "LLLL" date formatting.
+     * @param locale Locale
+     * @return Long names of months
+     */
+    static String[] getStandaloneLongMonths(final Locale locale) {
+        // Unfortunately standalone month names are not available in DateFormatSymbols,
+        // so we have to extract them.
+        final Calendar calendar = Calendar.getInstance(locale);
+        final int monthCount = calendar.getMaximum(Calendar.MONTH) + 1;
+        final String[] monthNames = new String[monthCount];
+        for (int i = 0; i < monthCount; i++) {
+            calendar.set(Calendar.MONTH, i);
+            monthNames[i] = calendar.getDisplayName(Calendar.MONTH, Calendar.LONG_STANDALONE, locale);
+        }
+        return monthNames;
+    }
+
+    /**
+     * Obtain short standalone month names as used in "LLLL" date formatting.
+     * @param locale Locale
+     * @return Short names of months
+     */
+    static String[] getStandaloneShortMonths(final Locale locale) {
+        // Unfortunately standalone month names are not available in DateFormatSymbols,
+        // so we have to extract them.
+        final Calendar calendar = Calendar.getInstance(locale);
+        final int monthCount = calendar.getMaximum(Calendar.MONTH) + 1;
+        final String[] monthNames = new String[monthCount];
+        for (int i = 0; i < monthCount; i++) {
+            calendar.set(Calendar.MONTH, i);
+            monthNames[i] = calendar.getDisplayName(Calendar.MONTH, Calendar.SHORT_STANDALONE, locale);
+        }
+        return monthNames;
+    }

Review Comment:
   sorry, I really should have noticed that before submitting. I'll refactor



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org