On Thu, 12 Oct 2023 06:01:41 GMT, Shaojin Wen <d...@openjdk.org> wrote:

>> Shaojin Wen has updated the pull request incrementally with one additional 
>> commit since the last revision:
>> 
>>   No longer localize printed numbers
>
> # Summary
> Keep the behavior of String.format('%tF') when printing LocalDate consistent 
> with the behavior of DateTimeFormatter.ISO_LOCAL_DATE.
> 
> 
> # Problem
> 1. When using String.format('%tF', localDate), use 
> get(ChronoField.YEAR_OF_ERA). When the value range is not [0,9999], the 
> behavior is inconsistent with DateTimeFormatter.ISO_LOCAL_DATE.format.
> 2. When String.format('%tF', localDate), Locale will be processed, which is 
> inconsistent with the standard.
> 
> * the year value range [-∞, -1] changes:
> ``` java
> String.format("%tF", LocalDate.of(-10000, 1, 1))
> // String.format 10001-01-01
> // DateTimeFormatter  -99999-01-01
> 
> 
> * the year value range [10000, +∞] changes:
> 
> String.format("%tF", LocalDate.of(10000, 1, 1)):
> // String.format 10000-01-01
> // DateTimeFormatter.format  +10000-01-01
> And the "%tF" format no longer handles Locale when printing numbers.
> 
> 
> 
> Locale.setDefault(
>         Locale.forLanguageTag("th-TH-u-nu-thai"));
> String.format("%tF", LocalDate.of(2001, 1, 1));
> // String.format ๒๐๐๑-๐๑-๐๑
> // DateTimeFormatter.ISO_LOCAL_DATE.format 2001-01-01
> 
> 
> # Solution
> 1. When String.format('%tF', localDate) uses ChronoField.YEAR instead of 
> ChronoField.YEAR_OF_ERA, when year > 9999, the prefix is added with '+'
> 2. And don't use Locale to print numbers.
> 
> 
> # Specification
> * [-∞, -1000]
> 
> String.format("%tF", LocalDate.of(-10000, 1, 1))
> // -10000-01-01
> 
> 
> The year value range [-999, -1], padded to 4 digits
> 
> String.format("%tF", LocalDate.of(-1, 1, 1))
> // -0001-01-01
> 
> 
> 
> The year value range [1, 9999], padded to 4 digits
> 
> String.format("%tF", LocalDate.of(1, 1, 1))
> // 0001-01-01
> 
> 
> * The year value range [10000, -∞], prefix prints '+'
> 
> String.format("%tF", LocalDate.of(10000, 1, 1))
> // +10000-01-01
> 
> 
> #  Risk
> 1. When String.format('%tF') processes 
> LocalDate/ZonedDateTime/OffsetDateTime, if the value range of year is not in 
> [0-9999], the output will be different from before.
> 2. When the Locale of String.format('%tF') is "th-TH-u-nu-thai", the printed 
> result is different from before.

@wenshao I fixed the spelling of "standard" in the JBS issue and CSR. Can you 
update the PR title as well? Thanks!

-------------

PR Comment: https://git.openjdk.org/jdk/pull/16033#issuecomment-1764222545

Reply via email to