Skip to content
This repository has been archived by the owner on Jan 25, 2022. It is now read-only.

Decide on the resolvedOptions for styles #49

Closed
zbraniecki opened this issue Jun 8, 2020 · 5 comments
Closed

Decide on the resolvedOptions for styles #49

zbraniecki opened this issue Jun 8, 2020 · 5 comments
Assignees

Comments

@zbraniecki
Copy link
Member

In issue #45 @anba pointed out that we should:

Modify Intl.DateTimeFormat.prototype.resolvedOptions to not output these fields when dateStyle or timeStyle is present.

That basically means that we will not returned resolved fields in resolved options:

let dtf = new Intl.DateTimeFormat(undefined, {
  dateStyle: "long"
});

// Option 1
dtf.resolvedOptions(); // {dateStyle: "long"}

// Option 2
dtd.resolvedOptions(); // {dateStyle: "long", "year": "numeric", month: "long", "day: "numeric"}

@sffc responded that:

It might be nice to have the fields be returned in resolvedOptions, rather than undefined. I find it a bit surprising that we currently return only dateStyle but not the fields to which the dateStyle resolved. I don't have a great sense of the consequences of this decision, though.

to which @anba responded that:

One consequence is that the resolved options can no longer be used to copy an Intl.DateTimeFormat instance, because of #43.

Let's discuss this decision here.

@sffc
Copy link

sffc commented Jun 8, 2020

We have some properties in Intl that get remapped; for example, style: "currency" causes fraction digits to be recalculated in Intl.NumberFormat.

One other approach here could be to not return dateStyle at all, and only return the fields. But, that might not roundtrip completely, due to the formatRange bug. However, hopefully that bug will be fixed soon on the CLDR side.

https://unicode-org.atlassian.net/browse/CLDR-13425

That would essentially be an Option 3:

let dtf = new Intl.DateTimeFormat(undefined, {
  dateStyle: "long"
});

// Option 3
dtd.resolvedOptions(); // {year: "numeric", month: "long", "day: "numeric"}

@zbraniecki
Copy link
Member Author

@littledan, @rxavier? - what's your take on this?

@littledan
Copy link
Member

littledan commented Jun 11, 2020

I would've expected option 1 to be the behavior. I thought this was the only possibility due to the shape of the CLDR data, since we go straight from the dateStyle/timeStyle to the pattern, no skeleton in the middle. Now, I see that's considered an issue by @sffc in https://unicode-org.atlassian.net/browse/CLDR-13425 :) Note that this spec does not really permit OS preferences from being taken into account; that's another way we could get a pattern with no real skeleton.

EDIT: Oh, looking back at the data model and #48, I see that Option 2 is fully possible. Not sure why I got confused. I'm still not sure whether Option 3 would reliably round-trip, though. I guess I'm OK with Option 2 not round-tripping--I don't think that's what resovedOptions is for anyway. So, I'm up for either Option 1 or 2.

@zbraniecki
Copy link
Member Author

At today's ECMA402 we recorded a consensus to go with Option 1.

@zbraniecki
Copy link
Member Author

The current PR has https://tc39.es/proposal-intl-datetime-style/#sec-intl.datetimeformat.prototype.resolvedoptions

If the Internal Slot value of the current row is an Internal Slot value in Table 1, then
    If dtf.[[DateStyle]] is not undefined or dtf.[[TimeStyle]] is not undefined, then
        Let v be undefined.

So, it seems like we are currently implementing Option 1 and this issue can be closed.

Reopen if needed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants