-
Notifications
You must be signed in to change notification settings - Fork 18
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
Negative durations in Intl.DurationFormat #29
Comments
I'm not sure if the relevant CLDR data exists, but returning an extra string containing what could be called the "adjacency modifier" based on the sign could be useful. This could be |
Playing devil's advocate: Instead of creating a new
Seems useful. Some languages may put the modifier before the duration text, while other languages might put it after. Some languages and modifiers could do both positions, e.g. "after 2 hours" vs. "2 hours after". How would the caller know where to put the modifier in the final text? |
I was thinking about that, too. I would rather have the class named |
One advantage of combining these into one class (regardless of the name): the option would be available to Temporal.Duration.prototype.toLocaleString. For example: const duration = Temporal.Duration.from("-PT3H5M");
duration.toLocaleString("pt-BR", { style: "relative" }); |
Yep, agreed. If starting from scratch, then If Some ideas for style names:
|
@pedberg-icu also pointed out one more style: |
Related feature request for mixed units in relative time format: tc39/ecma402#498 |
By "mixed units" I'm assuming that you mean multiple units in one string, not units with different signs from each other. Correct? |
Right. |
From my perspective, there are two options:
@ryzokuken suggested to have something in between. |
@justingrant could you state the three options here ? |
Summary from 2020-08-27 meeting:
Per consensus at the meeting that we should be proposing opinions along with options ;-), my preference is for 3.1 because:
|
On point 1, I do want to point out that CLDR does not currently support relative time formatting with more than one unit. However, we've gotten some requests for this (see tc39/ecma402#498). I am tracking this in CLDR-14144. On point 2, I suggested a fourth style in #29 (comment). I don't want to express an opinion on point 3 at this time. I have this on the agenda to discuss in the next 402 meeting. |
Discussion from 2020-09-10 TC39-TG2 meeting: |
Intl.DurationFormat is chartered to format the "amount" of time, not a "particular time in the timeline" A duration itself is a "amount of time" , without any reference point of start or end. 5 days mean a duration of 5 days of any 5 days in the timeline. It could be 5 days 2000 years ago, it could be the 5 days two months ago, it could be the 5 days starting 2 days ago and we are still in, or a 5 days 3 days from now. The formatted output of the duration of 5 days should not need to have a reference point and the result should not imply there is one. The duration could be given to a RelativeTimeFormat as input argument if we change the Intl.RelativeTimeFormat to accept it as an acceptable data type, in that case, since the current semantic of the Intl.RelativeTimeFormat is the output should means a particular time in the timeline relative to now, the formatted result should represent a particular time in the timeline relative to NOW after the operation between the time NOW and the passed in duration. So if the duration passed is -1 days, then the output could be "Yesterday", -2 hours, could be "two hours ago", 3 days could be "the day after tomorrow". If we extend the RelativeTimeFormat to give a different reference point, say "Jan 20, 2020", then format(100, "days") could be "100 days after Jan 20, 2020" and a duration of -5 days would be "five days before Jan 20, 2020". In either case, it still represent a particular time in the timeline, just change the reference point, but there are still a reference point. And it is not expression a "duration", but the result of that after we apply an operation of that "duration" to a reference point in the timeline. It should not be used to express an "amount" but only a "particular time". The name of expression the "duration" (amount) should not use ambiguous term "absolute", because the term "absolute" mean two different thing:
|
I believe the toLocaleString of the duration should only format the output as the duration itself, not a result of applying it to an operation. For example, the format output of 3 should only represent 3, not sqrt(3) or -3 by applying 3 to a different operation. In the same way, a duration of 3 day should format the output represent itself, but not the meaning of applying that to a operation, such as comparing to Now, or comparing /reference to another date in the timeline. Therefore, the toLocaleString of duration should always result to mean an "amount of time" not a "particular time in the timeline". |
My understanding of consensus in the meeting was that the default toLocaleString output for a negative duration should be: @FrankYFTang are you OK with those three criteria? |
I agree with a) |
My understanding is that this is beyond the scope of |
This is not obsolete. DurationFormat needs to format negative durations since Temporal.Duration supports negatives. I think we agreed to go with the format Justin proposed above in #29 (comment) |
@sffc is this already handled on the CLDR side? |
I think the scope of this issue for 402 is just to make sure that CLDR is aware of the sign of the duration when generating its implementation-defined output. It would also be good to have Test262 tests to verify that the output of a positive duration and the equivalent negative duration are not the same. |
Maybe this is an implementation question that doesn't belong here, but what exactly do you mean by "make sure that CLDR is aware of the sign of the duration when generating its implementation-defined output"? Would that involve changes in the ICU API to make Or do you mean something else by that? |
The exact localized format is implementation- and locale-defined (ILD). However, on our side, we should:
|
This is solved by #101, which disallows mixed-sign durations like Temporal and implementations can handle the rest, right? |
@justingrant tc39/test262#3593 should be merged soon. |
Temporal.Duration is going to support negative durations (tc39/proposal-temporal#782). What does this mean for Intl.DurationFormat when we get a negative duration?
Is there a standard localized format for negative durations? In the other thread, I asked:
The text was updated successfully, but these errors were encountered: