alhudz commented on code in PR #1815:
URL: https://github.com/apache/commons-lang/pull/1815#discussion_r4280391647


##########
src/main/java/org/apache/commons/lang3/time/FastDatePrinter.java:
##########
@@ -1591,6 +1598,38 @@ protected List<Rule> parsePattern() {
         return rules;
     }
 
+    /**
+     * Tests whether the month is the only field in the pattern.
+     * <p>
+     * {@link SimpleDateFormat} formats the text month of such a pattern with 
the standalone month names, which in some languages, like the Slavic and Baltic
+     * ones, are a different grammatical form from the names used next to a 
day ("{@code MMMM}" alone prints Russian February as nominative
+     * "{@code февраль}" where "{@code d MMMM}" prints genitive "{@code 
февраля}").
+     * </p>
+     *
+     * @return Whether the pattern contains exactly one field, the month.
+     */
+    private boolean isMonthOnlyPattern() {
+        final int[] indexRef = new int[1];
+        boolean monthField = false;
+        for (int i = 0; i < pattern.length(); i++) {
+            indexRef[0] = i;
+            final String token = parseToken(pattern, indexRef);
+            i = indexRef[0];
+            if (token.isEmpty()) {
+                break;
+            }
+            final char c = token.charAt(0);
+            if (c == '\'') {
+                continue;
+            }
+            if (c != 'M' || monthField) {
+                return false;
+            }

Review Comment:
   This already holds: `parseToken` returns any non-letter run with a leading 
`'`, the same as a quoted literal, so `isMonthOnlyPattern()` skips `MMMM,` or 
`MMMM-` and treats them as month-only. No change needed.



##########
src/test/java/org/apache/commons/lang3/time/FastDatePrinterTest.java:
##########
@@ -210,6 +214,36 @@ void testEraNonGregorianCalendar() {
         }
     }
 
+    /**
+     * Tests that a month-only pattern uses the standalone month names, like 
SimpleDateFormat. In some languages, like the Slavic and Baltic ones, they are a
+     * different grammatical form from the names used next to a day: "MMMM" 
alone prints Russian February as nominative "февраль" where "d MMMM" prints
+     * genitive "февраля".
+     */
+    @Test
+    void testStandaloneMonthForMonthOnlyPattern() throws ParseException {
+        // SimpleDateFormat forces the standalone form for a month-only 
pattern only since Java 9 (JDK-8114833); Java 8 has no such rule.
+        assumeTrue(SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_9));
+        final Locale[] locales = { Locale.US, Locale.GERMANY, new 
Locale("ru"), new Locale("cs"), new Locale("pl"), new Locale("fi") };
+        // Month-only patterns, with or without literals, use the standalone 
form; patterns with another field keep the format form.
+        final String[] patterns = { "MMM", "MMMM", "'m:'MMMM", "MMMM''", "d 
MMMM", "MMMM yyyy", "MMM MMM" };

Review Comment:
   Covered by the `MMMM,` pattern now in the test. It passes against 
`SimpleDateFormat` with no change to the helper.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to