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

Represent 0 differently from "missing" in durations? #564

Closed
littledan opened this issue May 13, 2020 · 3 comments
Closed

Represent 0 differently from "missing" in durations? #564

littledan opened this issue May 13, 2020 · 3 comments

Comments

@littledan
Copy link
Member

In Intl.DurationFormat, there are controls for which fields are displayed. One possibility is that this is phrased in terms of a "fields" option, with dash-separated field names. Another option is to list lower and upper fields, as described in tc39/proposal-intl-duration-format#2 .

For a different approach: What if the data model for Temporal.Duration treated 0 differently from null/undefined? Then, Intl.DurationFormat wouldn't need the fields to be specified, and could just format all of the fields that the Duration contains.

As a straw-person, I could imagine that .with({minute: null}) could remove the minute field (since undefined would be ignored).

cc @sffc @younies

@sffc
Copy link
Collaborator

sffc commented May 13, 2020

This could work mechanically with regard to Intl.DurationFormat. I'm not sure about all of the implications. We should look at this alongside #337.

@ptomato
Copy link
Collaborator

ptomato commented May 13, 2020

I'm not a fan of this for two reasons:

  • It's awkward with serialization, since P0Y0M1DT0H0M0S and P1D are defined to represent the same duration but we'd be treating them differently. Furthermore, { milliseconds: null, microseconds: 0 } would not be serializable.
  • It doesn't affect any of the calculations in Temporal. Unspecified would always be treated as 0. The only thing it affects is formatting, which to me is an indication that the functionality belongs in Intl.DurationFormat.

@littledan
Copy link
Member Author

I'm pretty convinced by @ptomato 's reasoning. If we go without a separate "missing" representation, I'm happy with @zbraniecki's suggestion for Intl.DurationFormation, removing the need for representing missing fields. I'm happy to drop this suggestion.

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

No branches or pull requests

3 participants