Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit attribute to the formatToParts output to match Intl.RelativeTimeFormat #27

Open
FrankYFTang opened this issue Mar 19, 2021 · 4 comments
Labels
enhancement New feature or request future Out of scope for the current proposal

Comments

@FrankYFTang
Copy link
Contributor

FrankYFTang commented Mar 19, 2021

let nf = new Intl.NumberFormat("en", {style: "unit", unit: "day"})
nf.format(3.4)
> "3.4 days"
nf.formatToParts(3.4)
>0: {type: "integer", value: "3"}
1: {type: "decimal", value: "."}
2: {type: "fraction", value: "4"}
3: {type: "literal", value: " "}
4: {type: "unit", value: "days"}

let rf = new Intl.RelativeTimeFormat("en")
rf.format(3.4, "day")
> "in 3.4 days"
rf.formatToParts(3.4, "day")
> 0: {type: "literal", value: "in "}
1: {type: "integer", value: "3", unit: "day"}
2: {type: "decimal", value: ".", unit: "day"}
3: {type: "fraction", value: "4", unit: "day"}
4: {type: "literal", value: " days"}

Notice the output from the Intl.RelativeTimeFormat has the unit: "day" in the integer/decimal/fraction
Should we also make the Intl.NumberFormat to output that ?

I think we should change the spec in NumberFormat v3 to make Intl.NumberFormat output

nf.formatToParts(3.4)
>0: {type: "integer", value: "3", unit: "day"}
1: {type: "decimal", value: ".", unit: "day"}
2: {type: "fraction", value: "4", unit: "day"}
3: {type: "literal", value: " "}
4: {type: "unit", value: "days"}

There is a second issue of the 4: {type: "literal", value: " days"} from the Intl.RelativeTimeFormat, which I think we should discuss in a ECMA402 issue.

@sffc
Copy link
Collaborator

sffc commented Mar 19, 2021

I think it would be great to do this, but ICU doesn't support this right now, and I don't want to block NFv3 on this feature, because I want NFv3 to ship with the current feature set based on ICU 69. I would rather consider it as an enhancement in a future proposal.

@sffc sffc added the enhancement New feature or request label Mar 19, 2021
@FrankYFTang
Copy link
Contributor Author

or maybe we should do

nf.formatToParts(3.4)
>0: {type: "integer", value: "3", unit: "day"}
1: {type: "decimal", value: ".", unit: "day"}
2: {type: "fraction", value: "4", unit: "day"}
3: {type: "literal", value: " ", unit: "day"}
4: {type: "unit", value: "days", unit: "day"}

to make it consistent with the future Intl.DurationFormat when there maybe multiple PARTS of different units in the output

@FrankYFTang
Copy link
Contributor Author

It won't require any ICU change to do

nf.formatToParts(3.4)
>0: {type: "integer", value: "3", unit: "day"}
1: {type: "decimal", value: ".", unit: "day"}
2: {type: "fraction", value: "4", unit: "day"}
3: {type: "literal", value: " ", unit: "day"}
4: {type: "unit", value: "days", unit: "day"}

we already know from the constructor the unit is day, and we just attach to all output nodes. Require no new ICU feature to implement that.

@sffc sffc added the future Out of scope for the current proposal label Nov 28, 2022
@sffc
Copy link
Collaborator

sffc commented Nov 28, 2022

This feature request largely fell through the cracks. I think this can still be added as a small normative PR against the spec after Stage 4. I will move this issue to the ecma402 repository after the proposal is merged in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request future Out of scope for the current proposal
Projects
None yet
Development

No branches or pull requests

2 participants