-
Notifications
You must be signed in to change notification settings - Fork 115
Open
Labels
c: datetimeComponent: dates, times, timezonesComponent: dates, times, timezoness: blockedStatus: the issue is blocked on upstreamStatus: the issue is blocked on upstream
Description
Problem: A user builds an Intl.DateTimeFormat with non-contiguous options. For example:
new Intl.DateTimeFormat("en", {
year: "numeric",
day: "numeric"
});What should the behavior be?
- Garbage in, garbage out. (current behavior)
- Throw an exception. (breaks the web)
- Fill in the missing fields: between year and day, automatically assume month. (best attempt for what the user might want)
A problem with "garbage in, garbage out" is that you can get the CLDR replacement pattern exposed, as @anba pointed out in #346 (comment). Here is a list of current outputs in Chrome 78:
const fields = ["year", "month", "day", "hour", "minute", "second"];
for (let i=0; i<fields.length; i++) {
for (let j=i+2; j<fields.length; j++) {
const options = {};
options[fields[i]] = "numeric";
options[fields[j]] = "numeric";
const fmt = new Intl.DateTimeFormat("en", options);
console.log(fields[i] + "/" + fields[j] + ": " + fmt.format(new Date()));
}
}
/*
year/day: 10 2019
year/hour: 2019, 3 PM
year/minute: 2019, 30
year/second: 2019, 33
month/hour: 12, 3 PM
month/minute: 12, 30
month/second: 12, 33
day/minute: 10, 30
day/second: 10, 33
hour/second: 3 PM (second: 33)
*/I have a slight preference for adopting behavior 3 (fill in the missing fields). This behavior would be fully spec-compliant as-is, since the patterns are implementation-defined, but we could further codify this behavior into the spec to provide clarity to users.
CLDR issue about minute + dayPeriod:
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
c: datetimeComponent: dates, times, timezonesComponent: dates, times, timezoness: blockedStatus: the issue is blocked on upstreamStatus: the issue is blocked on upstream
Type
Projects
Status
Previously Discussed