[ 
https://issues.apache.org/jira/browse/LANG-1680?focusedWorklogId=770531&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-770531
 ]

ASF GitHub Bot logged work on LANG-1680:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 14/May/22 22:55
            Start Date: 14/May/22 22:55
    Worklog Time Spent: 10m 
      Work Description: 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`





Issue Time Tracking
-------------------

    Worklog Id:     (was: 770531)
    Time Spent: 2h 10m  (was: 2h)

> FastDateFormat does not support the 'L'-Pattern from SimpleDateFormat
> ---------------------------------------------------------------------
>
>                 Key: LANG-1680
>                 URL: https://issues.apache.org/jira/browse/LANG-1680
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.time.*
>    Affects Versions: 3.12.0
>         Environment: All
>            Reporter: Michael Krause
>            Priority: Minor
>          Time Spent: 2h 10m
>  Remaining Estimate: 0h
>
> The MMM-Pattern in SimpleDateFormat is context-sensitve. 
> If you execute
> {{{{FastDateFormat.getInstance("MMMyy", 
> Locale.GERMAN).format(Calendar.getInstance())}}}}
> You get "Jan.22". Observer the dot after 'Jan'.  If you do the equivalent 
> with SimpleDateFormat with 'LLLyy' instead as the pattern 
> {{{{new SimpleDateFormat("LLLyy", 
> Locale.GERMANY).format(Calendar.getInstance().getTime());}}}}
> you get "Jan22" as expected. 
>  
> If the 'L'-Pattern is used with FastDateFormat, it throws an 
> IllegalArgumentException
> {{java.lang.IllegalArgumentException: Illegal pattern component: LLL}}{{    
> at 
> org.apache.commons.lang3.time.FastDatePrinter.parsePattern(FastDatePrinter.java:311)}}{{
>  }}
> {{The Source shows that the L-Pattern is not implemented.}}
>  
>  



--
This message was sent by Atlassian Jira
(v8.20.7#820007)

Reply via email to