new Intl.DateTimeFormat("ja", { month: "short", day: "numeric" }).format(0);
// "1月1日"
new Intl.DateTimeFormat("ja", { month: "short", day: "numeric" }).format(Temporal.PlainDateTime.from("1970-01-01"));
// "1/1"
(note: V8 also has this problem for some reason. SpiderMonkey doesn't.)
This is because options in Intl.DateTimeFormat and resolvedOptions are not roundtrippable for some cases:
new Intl.DateTimeFormat("ja", { month: "short", day: "numeric" }).resolvedOptions().month;
// "numeric", not "short"
new Intl.DateTimeFormat("ja", { month: "numeric", day: "numeric" });
// different format is chosen when recreating `Intl.DateTimeFormat` from the return value of `resolvedOptions`
I found many combinations of locales and options which produce different result for Temporal classes and Date. I verified this on Node.js and Firefox. Some of them are practically nonsense (e.g. combination of era and month), but still there are bunch of cases.
// Turkish
new Intl.DateTimeFormat('tr', { year: 'numeric', month: 'numeric' }).resolvedOptions().month;
// "2-digit", not "numeric"
new Intl.DateTimeFormat('tr', { year: 'numeric', month: 'numeric' }).format(0);
// "01/1970"
new Intl.DateTimeFormat('tr', { year: 'numeric', month: 'numeric' }).format(Temporal.PlainDateTime.from('1970-01-01'));
// "01.1970"
Script I used to discover these exceptions: https://gist.github.com/fabon-f/d6b22aa3d3c816cabdea2510c8d9b322
(note: V8 also has this problem for some reason. SpiderMonkey doesn't.)
This is because options in
Intl.DateTimeFormatandresolvedOptionsare not roundtrippable for some cases:I found many combinations of locales and options which produce different result for Temporal classes and
Date. I verified this on Node.js and Firefox. Some of them are practically nonsense (e.g. combination oferaandmonth), but still there are bunch of cases.Script I used to discover these exceptions: https://gist.github.com/fabon-f/d6b22aa3d3c816cabdea2510c8d9b322