-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
11.0.6
-
x86_64
-
windows_10
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
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
- relates to
-
JDK-8244245 localizedBy() should override localized values with default values
-
- Closed
-