ecma402 icon indicating copy to clipboard operation
ecma402 copied to clipboard

How to format "0.50 days", "0.25 hours", or "3.25 minutes" in DurationFormat

Open FrankYFTang opened this issue 3 years ago • 12 comments

I am reading the spec about "fractionalDigits" but I cannot figure out how to create an object to formating someting like "0.50 days", "1.25 hours", or "3.25 minutes" w/ {fractionalDigits:2} . Is that intentionally unsupported?

@sffc @ryzokuken

FrankYFTang avatar Dec 29 '21 06:12 FrankYFTang

@FrankYFTang yes. In the case of days, it's hard to say how many hours constitute 0.5 days, since not all days are equally long. In the case of smaller units, Temporal assumes all units are of fixed size for now but this might not hold in the future when (and if at all) we decide to add support for alternate time-keeping systems like we currently support alternate calendars.

Therefore, only seconds and below can be represented as fractions for now but we'd debated loosening that upto hours (but decided not to allow it yet).

ryzokuken avatar Dec 29 '21 06:12 ryzokuken

Duplicate of https://github.com/tc39/proposal-intl-duration-format/issues/65, I think.

sffc avatar Dec 29 '21 07:12 sffc

@FrankYFTang yes. In the case of days, it's hard to say how many hours constitute 0.5 days, since not all days are equally long.

I understand for a specific date, the number of hours may not be 24, but for a unit of "day" for the purpose of formatting why is it not 24 hours? Also, how about "0.25 hours", or "3.25 minutes". In what sense that 15 minutes not be counted as "0.25 hours" and 195 seconds not counted as "3.25 minutes"?

FrankYFTang avatar Dec 29 '21 22:12 FrankYFTang

It is a valid use case that is not supported right now.

I'm okay punting this to DurationFormat v2, unless it requires breaking something we've done in v1.

@ryzokuken Can you verify that we have a path forward for supporting this feature in a future proposal in a backwards-compatible way?

sffc avatar Dec 30 '21 00:12 sffc

Discussion 2021-01-13: https://github.com/tc39/ecma402/blob/master/meetings/notes-2022-01-13.md#how-to-format-050-days-025-hours-or-325-minutes-89

Conclusion: @ryzokuken to come up with a spec text modification to demonstrate this possibility, but we will not put it into the current proposal.

sffc avatar Jan 13 '22 20:01 sffc

I think the current spec satisfies fractional numeric formatting well enough, right?

ryzokuken avatar Jun 30 '22 17:06 ryzokuken

No, we don't support fractions of anything other than seconds. The ask here is to show how a potential Intl.DurationFormat V2 proposal could add fractional formatting of other units.

sffc avatar Jul 02 '22 01:07 sffc

No, we don't support fractions of anything other than seconds.

hum... I though the current spec said j. If unit is "seconds", "milliseconds", or "microseconds"

not just seconds.

FrankYFTang avatar Jul 13 '23 01:07 FrankYFTang

True; it works for seconds, milliseconds, and microseconds.

I think this issue is waiting on action from @ryzokuken.

sffc avatar Jul 13 '23 09:07 sffc

For example, would it be possible in the future to start accepting { seconds: "numeric" } and have expected behavior? How does that interact with digital style?

sffc avatar Aug 23 '23 21:08 sffc

We discussed some potential approaches in the November 2024 call (and previously). We think it can be fairly easily added in v2, and spec refactors that @ben-allen is working on should make it implementable.

sffc avatar Nov 16 '23 19:11 sffc

Notes from November 2024 call: https://github.com/tc39/ecma402/blob/master/meetings/notes-2023-11-16.md#style-fractional

sffc avatar Nov 16 '23 22:11 sffc