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

Handling wrong arguments for digital format #33

Closed
younies opened this issue Aug 24, 2020 · 13 comments
Closed

Handling wrong arguments for digital format #33

younies opened this issue Aug 24, 2020 · 13 comments

Comments

@younies
Copy link
Member

younies commented Aug 24, 2020

For digital format we only have limited fields to format and we do not suggest having zero values in the middle, what shall we do in the case of wrong arguments

For example, if a user wants to format largestUnit: "days", smallestUnit: "seconds"

in this case, shall we reject or flip to another format such as short

@sffc
Copy link
Collaborator

sffc commented Sep 10, 2020

Discussion from 2020-09-10:

SFC: We could fall back, or we throw.

PFC: My inclination is that we should throw.

JSW: I agree about throwing.

SFC: You don't know whether your duration has days until you get it and try to format it.

FYT: Why do we need the dotted format in the first place?

YMD: It's used in video games.

FYT: How do you pick between the three types of dotted formats, hm, hms, and ms?

YMD: They are all dotted.

FYT: I don't see where you specify the largest and smallest fields in the spec.

SFC: The Stage 2 proposal uses an array instead of largestUnit/smallestUnit.

FYT: I don't know what this looks like. I would like to see code samples to compare the behavior. You asked a question that's neither in the spec nor reflected in code. Look at the Unified NumberFormat proposal or DisplayNames. On issues, we post code to discuss.

@younies younies added the spec label Feb 2, 2021
@FrankYFTang
Copy link
Collaborator

FrankYFTang commented Mar 19, 2021

can someone explain to me what would be expected output of the following

let d = {years: 1, months: 2, weeks: 3, days: 4, hours:5, minutes:6, seconds: 7}
let d2 = {hours:5, minutes:6}
let d3 = {minutes:5, seconds:6}

let df1 = new Intl.DurationFormat("en", {style: "digital"})
let df2 = new Intl.DurationFormat("en", {style: "digital", smallestUnit: "seconds", largestUnit: "hours"})

df1.format(d) // line1
df2.format(d) // line2
df1.format(d2) // line3
df2.format(d2) // line4
df1.format(d3) // line5
df2.format(d3) // line6

@younies younies changed the title Handling wrong arguments for dotted format Handling wrong arguments for digital format Mar 19, 2021
@younies
Copy link
Member Author

younies commented Mar 19, 2021

we agreed that digital format is only for hours, minutes and seconds. However, we need to determine what the output should be in case of wrong arguments.

I think we kinda slip this part somehow.

@younies younies added the Meeting Discussion Need to be discussed in one of the upcoming meetings label Mar 19, 2021
@FrankYFTang
Copy link
Collaborator

FrankYFTang commented Mar 19, 2021

we agreed that digital format is only for hours, minutes and seconds. However, we need to determine what the output should be in case of wrong arguments.

Based on the agreement you said above, what should be the output of

let d = {years: 1, months: 2, weeks: 3, days: 4, hours:5, minutes:6, seconds: 7}
let d2 = {hours:5, minutes:6}
let d3 = {minutes:5, seconds:6}

let df1 = new Intl.DurationFormat("en", {style: "digital"})
let df2 = new Intl.DurationFormat("en", {style: "digital", smallestUnit: "seconds", largestUnit: "hours"})

df1.format(d) // line1
df2.format(d) // line2
df1.format(d2) // line3
df2.format(d2) // line4
df1.format(d3) // line5
df2.format(d3) // line6

There are many possibility behavior of interpreting such agreement. Could you write down, based on your understanding of the agreement, what the output should be exactly?

@ryzokuken ryzokuken removed the spec label Apr 5, 2021
@ryzokuken ryzokuken added this to the Stage 3 milestone Apr 5, 2021
@ryzokuken ryzokuken added Under discussion and removed Meeting Discussion Need to be discussed in one of the upcoming meetings labels Apr 5, 2021
@ryzokuken
Copy link
Member

@FrankYFTang given that we will limit the valid values for "smallestUnit" and "largestUnit" and that they will be appropriately forwarded to Duration.p.round, I suppose this will be a non-issue now?

@FrankYFTang
Copy link
Collaborator

I cannot tell it would be an issue or not without seeing exactly what the spec text would turn into and what would be the output of

let d = {years: 1, months: 2, weeks: 3, days: 4, hours:5, minutes:6, seconds: 7}
let d2 = {hours:5, minutes:6}
let d3 = {minutes:5, seconds:6}

let df1 = new Intl.DurationFormat("en", {style: "digital"})
let df2 = new Intl.DurationFormat("en", {style: "digital", smallestUnit: "seconds", largestUnit: "hours"})

df1.format(d) // line1
df2.format(d) // line2
df1.format(d2) // line3
df2.format(d2) // line4
df1.format(d3) // line5
df2.format(d3) // line6

From your understanding of what we already agree upon, what would be the output of these 6 lines?

@ryzokuken
Copy link
Member

Now I am not 100% sure of it myself, given that folks have pointed out "digital" formats that can display units larger than "hours", but given my previous assumption that CLDR only includes data for this format upto "hours", here is the result:

RangeError // line1 (larger than hours cannot be rounded implicitly, you need to round explicitly with a `relativeTo` value)
RangeError // line2 (same as above)
05:00:06 // line3
05:00:06 // line4
00:05:06 // line5
00:05:06 // line6

Now this assumes that we expand the current behavior to "smallestUnit", "largestUnit" and "hideZeroValues", that is, they are all hardcoded based on "style". If we decide to choose more interesting defaults, maybe like an "auto" option that looks for the smallest/largest available value or just a good "hideZeroValues" default, line5 would become 05:06 instead. All other lines will stay the same.

@FrankYFTang
Copy link
Collaborator

let d2 = {hours:5, minutes:6}

why is the following? that is for {hours:5, seconds:6} not {hours:5, minutes:6}

05:00:06 // line3
05:00:06 // line4

@ryzokuken
Copy link
Member

@FrankYFTang oops, sorry, I misread. In that case, it would be

05:06:00 // line3
05:06:00 // line4

and given my argument about defaults, line3 could become 05:06 as well.

Now if I understand correctly, your point is that in that case line3 and line5 would be the same (05:06) but essentially mean different things. As Shane pointed out, it could be different for some locales. But for the locales that it isn't different, I still feel that this is okay. It is the responsibility of the developer to make sure that the value displayed at the end is unambiguous, either based on additional information or contextual clues like @younies suggested.

@ryzokuken
Copy link
Member

@FrankYFTang oh wait that was #54. So this issue basically needs no resolving, it will be resolved automatically when we start rounding things properly.

@ryzokuken ryzokuken added the units label Apr 8, 2021
@FrankYFTang
Copy link
Collaborator

FrankYFTang commented Apr 8, 2021

I am not asking these 6 lines to make any points here. I just try to understand what will be the output from your agreed changes (since I have no spec text to follow to figure out yet).

@ryzokuken
Copy link
Member

@FrankYFTang right, sorry, I will make the spec text updates as soon as possible while the surrounding questions get answered.

@ryzokuken
Copy link
Member

"wrong" arguments are no longer permitted in the current design. closing.

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

No branches or pull requests

4 participants