<i18n dev> RFR: JDK-8318761: MessageFormat pattern support for CompactNumberFormat, ListFormat, and DateTimeFormatter [v8]

Justin Lu jlu at openjdk.org
Fri Feb 9 23:20:30 UTC 2024


> Please review this PR and [CSR](https://bugs.openjdk.org/browse/JDK-8319344) which adds MessageFormat pattern support for the following subformats: ListFormat, CompactNumberFormat, and DateTimeFormatter. This change is intended to provide pattern support for the more recently added JDK Format subclasses, as well as improving java.time formatting within i18n. The draft javadoc can be viewed here: https://cr.openjdk.org/~jlu/docs/api/java.base/java/text/MessageFormat.html. Please see the CSR for more in-depth behavioral changes, as well as limitations.
> 
> The `FormatTypes`:  dtf_date, dtf_time, dtf_datetime, pre-defined DateTimeFormatter(s), and list are added.
> The `FormatStyles`: compact_short, compact_long, or, and unit are added.
> 
> For example, previously,
> 
> 
> Object[] args = {LocalDate.of(2023, 11, 16), LocalDate.of(2023, 11, 27)};
> MessageFormat.format("It was {0,date,full}, now it is {1,date,full}", args);
> 
> 
> would throw `Exception java.lang.IllegalArgumentException: Cannot format given Object as a Date`
> 
> Now, a user can call
> 
> 
> MessageFormat.format("It was {0,dtf_date,full}, now it is {1,dtf_date,full}", args);
> 
> 
> which returns "It was Thursday, November 16, 2023, now it is Friday, November 17, 2023"

Justin Lu has updated the pull request with a new target base due to a merge or a rebase. The pull request now contains 12 commits:

 - white space tweak for spec
 - Merge branch 'master' into JDK-8318761-j.text.MessageFormat-pattern-enh
 - implement Naoto's review
 - Move the if-else nFmt checking to a package-private method in NumberFormat
 - Merge remote-tracking branch 'origin/JDK-8318761-j.text.MessageFormat-pattern-enh' into JDK-8318761-j.text.MessageFormat-pattern-enh
 - Apply spacing suggestions
   
   Co-authored-by: Andrey Turbanov <turbanoff at gmail.com>
 - implement some feedback from Roger's comments
 - merge master and resolve conflicts stemming from 8323699
 - add expected message to exception checking
 - Use Naoto's recommended example
 - ... and 2 more: https://git.openjdk.org/jdk/compare/3ebe6c19...ee36eebb

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

Changes: https://git.openjdk.org/jdk/pull/17663/files
 Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=17663&range=07
  Stats: 1258 lines in 7 files changed: 929 ins; 197 del; 132 mod
  Patch: https://git.openjdk.org/jdk/pull/17663.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/17663/head:pull/17663

PR: https://git.openjdk.org/jdk/pull/17663


More information about the i18n-dev mailing list