Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8243162

DateTimeFormatter formatted numbers are not localized

    Details

    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      windows_10

      Description

      ADDITIONAL SYSTEM INFORMATION :
      AdoptOpenJDK version 11.0.6

      A DESCRIPTION OF THE PROBLEM :
      The java.time.format.DateTimeFormatter does not work correctly for locales that use different symbols to represent numbers.

      This bug has not been detected probably because languages such as English, French, Spanish and... use the same symbols and characters to represent numbers. Languages such as Persian (also called Farsi), Arabic (a widely spoken language) and maybe some others use different symbols and Unicode characters to represent numbers:
      Western numerals: 1 2 3 4 5 6 7 8 9 0
      Persian numerals: Û± Û² Û³ Û´ Ûµ Û¶ Û· Û¸ Û¹ Û°

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      public static void main(String[] args) {
          DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy", Locale.forLanguageTag("fa"));
          System.out.println(formatter.format(LocalDate.now()));
      }

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The above code should print Û²Û°Û²Û°...
      ACTUAL -
      ... but it prints 2020.

      CUSTOMER SUBMITTED WORKAROUND :
      The "DateFormat" class that is used to format Java legacy "Date"s works as expected:
          SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy", Locale.forLanguageTag("fa"));
          System.out.println(dateFormatter.format(new Date())); // Correctly prints Û²Û°Û²Û°

      It seems that only NUMBERS are not localized properly; other things seem to be working. For example:
          DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMM", Locale.forLanguageTag("fa"));
          System.out.println(formatter.format(LocalDate.now()));
      ... prints "آوریل" (==April) correctly.

      The problem may be resolved if internal methods that return numbers (such as year, month, etc) format the number with the given locale (the locale that the user specified in DateTimeFormatter). Like this:
          return NumberFormat.getNumberInstance(/*The Locale*/).format(123);

      FREQUENCY : always


        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                naoto Naoto Sato
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: