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 22:55:48 UTC

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

arturobernalg commented on code in PR #892:
URL: https://github.com/apache/commons-lang/pull/892#discussion_r873082991


##########
src/main/java/org/apache/commons/lang3/time/DateUtils.java:
##########
@@ -1831,4 +1832,40 @@ public void remove() {
         }
     }
 
+    /**
+     * Gets full standalone month names as used in "LLLL" date formatting.
+     * @param locale Locale
+     * @return Long names of months
+     */
+    static String[] getStandaloneLongMonths(final Locale locale) {
+        return getMonthNames(locale, Calendar.LONG_STANDALONE);
+    }
+
+    /**
+     * Gets short standalone month names as used in "LLLL" date formatting.
+     * @param locale Locale
+     * @return Short names of months
+     */
+    static String[] getStandaloneShortMonths(final Locale locale) {
+        return getMonthNames(locale, Calendar.SHORT_STANDALONE);
+    }
+
+    /**
+     * Gets month names in the requested style.
+     * @param locale Locale
+     * @param style Must be a valid {@link Calendar#getDisplayNames(int, int, Locale)} month style.
+     * @return Styled names of months
+     */
+    private static String[] getMonthNames(final Locale locale, final int style) {
+        // Unfortunately standalone month names are not available in DateFormatSymbols,
+        // so we have to extract them.
+        final Calendar calendar = Calendar.getInstance(locale);
+        Map<String, Integer> displayNames = calendar.getDisplayNames(Calendar.MONTH, style, locale);

Review Comment:
   add final



##########
src/main/java/org/apache/commons/lang3/time/DateUtils.java:
##########
@@ -1831,4 +1832,40 @@ public void remove() {
         }
     }
 
+    /**
+     * Gets full standalone month names as used in "LLLL" date formatting.
+     * @param locale Locale
+     * @return Long names of months
+     */
+    static String[] getStandaloneLongMonths(final Locale locale) {
+        return getMonthNames(locale, Calendar.LONG_STANDALONE);
+    }
+
+    /**
+     * Gets short standalone month names as used in "LLLL" date formatting.
+     * @param locale Locale
+     * @return Short names of months
+     */
+    static String[] getStandaloneShortMonths(final Locale locale) {
+        return getMonthNames(locale, Calendar.SHORT_STANDALONE);
+    }
+
+    /**
+     * Gets month names in the requested style.
+     * @param locale Locale
+     * @param style Must be a valid {@link Calendar#getDisplayNames(int, int, Locale)} month style.
+     * @return Styled names of months
+     */
+    private static String[] getMonthNames(final Locale locale, final int style) {
+        // Unfortunately standalone month names are not available in DateFormatSymbols,
+        // so we have to extract them.
+        final Calendar calendar = Calendar.getInstance(locale);
+        Map<String, Integer> displayNames = calendar.getDisplayNames(Calendar.MONTH, style, locale);
+        final String[] monthNames = new String[displayNames.size()];
+        for (Map.Entry<String, Integer> entry: displayNames.entrySet()) {

Review Comment:
   `final Map.Entry<String, Integer> entry`



-- 
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