RFR: 8317742: ISO Starndard Date Format implementation consistency on DateTimeFormatter and String.format
温绍锦
duke at openjdk.org
Mon Oct 9 18:55:19 UTC 2023
On Wed, 4 Oct 2023 11:33:16 GMT, Claes Redestad <redestad at openjdk.org> wrote:
> I think this deserves a discussion on the mailing list before jumping to a PR, as neither `%tF` nor the ISO-8601 standard it defers to is particularly well-defined outside of the range 0-9999
Thank you @cl4es for your suggestion, I have sent an email to mailing.
j.t.DateTimeFormatter defines ISO_LOCAL_DATE, j.u.Formatter.DateTime also defines ISO_STANDARD_DATE ("%tF"), and now their behavior is different outside the range of [0,9999], We run the following code and we can see their different behaviors:
DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_DATE;
int[] years = {-99999, -9999, -999, -99, -9, 0, 9, 99, 999, 1999, 2999, 9999, 99999};
for (int year : years) {
LocalDate localDate = LocalDate.of(year, 1, 1);
System.out.println(formatter.format(localDate) + "\t\t->\t\t" + "%tF".formatted(localDate));
}
* output
-99999-01-01 -> 100000-01-01
-9999-01-01 -> 10000-01-01
-0999-01-01 -> 1000-01-01
-0099-01-01 -> 0100-01-01
-0009-01-01 -> 0010-01-01
0000-01-01 -> 0001-01-01
0009-01-01 -> 0009-01-01
0099-01-01 -> 0099-01-01
0999-01-01 -> 0999-01-01
1999-01-01 -> 1999-01-01
2999-01-01 -> 2999-01-01
9999-01-01 -> 9999-01-01
+99999-01-01 -> 99999-01-01
-------------
PR Comment: https://git.openjdk.org/jdk/pull/16033#issuecomment-1746990262
More information about the core-libs-dev
mailing list