Proposal-temporal: Possible bug in Temporal.Duration.from => PT23H60M59S

Created on 14 Jul 2020  路  6Comments  路  Source: tc39/proposal-temporal

The value of duration shouldn't be PT24H59S or PT24H1M59S ?

Temporal.Duration.from({ hours: 23, minutes: 59, seconds: 59 }).plus({ minutes : 1}).toString();
//=> PT23H60M59S

Did not had a read on the spec to determine if this is a bug or intentional

documentation

Most helpful comment

Right, the units in Temporal.Duration don't naturally wrap-around back to 0 because you may want to have a duration of "90 minutes", for example, and you don't want it to unexpectedly turn into "1 hour 30 minutes". There is also #337 open for defining a rounding and balancing API for Temporal.Duration.

I think we should keep this issue open and use it to improve the documentation on this point. @romulocintra Do you have any suggestions about where it might have helped to explain this in the documentation?

All 6 comments

The default behavior is to "constrain" and "balance" isn't accepted. @ptomato may be able to better explain why that's the case.

Related: #645 suggests to have a balancing option on .plus just like we have on minus today. I'd suggest closing this issue (because it's behaving as designed) and continuing the discussion over in #645.

Right, the units in Temporal.Duration don't naturally wrap-around back to 0 because you may want to have a duration of "90 minutes", for example, and you don't want it to unexpectedly turn into "1 hour 30 minutes". There is also #337 open for defining a rounding and balancing API for Temporal.Duration.

I think we should keep this issue open and use it to improve the documentation on this point. @romulocintra Do you have any suggestions about where it might have helped to explain this in the documentation?

Right, the units in Temporal.Duration don't naturally wrap-around back to 0 because you may want to have a duration of "90 minutes", for example, and you don't want it to unexpectedly turn into "1 hour 30 minutes". There is also #337 open for defining a rounding and balancing API for Temporal.Duration.

Thanks @ptomato for this excellent explanation, I raised this issue cause I'm used with the behaviour of moment or dayJS and I found this "different" or counter-intuitive at first without the correct context:

moment.duration({ hours: 23, minutes: 59, seconds: 59 }).add(1,'minute').toString();
//=> PT24H59S

I think we should keep this issue open and use it to improve the documentation on this point. @romulocintra Do you have any suggestions about where it might have helped to explain this in the documentation?

Documentation(Cookbook) is great, the Disambiguation part helped me to understand, I got little lost because when you are going through all Cookbook and almost every method has a Disambiguation section you just jump without seeing the details of each particular explanation.

As a constructive suggestion Resolving ambiguity should have more visibility.

BTW applying Disambiguation :

duration = Temporal.Duration.from({ hours: 23, minutes: 59, seconds: 59 }).plus({ minutes : 1 });
duration.with(duration, { disambiguation: 'balance' }).toString();
//=> P1DT59S

@romulocintra I've attempted to make this more visible in #777, please let me know what you think!

@romulocintra I've attempted to make this more visible in #777, please let me know what you think!

Clear !!! thks @ptomato great work !!!

Was this page helpful?
0 / 5 - 0 ratings