-
Notifications
You must be signed in to change notification settings - Fork 152
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
Duration.prototype.round spec text has unused variables, errors #1379
Comments
Fix bug where largestUnit: 'auto' is considered to be no unit provided. Fixes #1379.
If the version espoused in the docs is what we want to do, then #1380 should implement that and is ready for review. |
I'm looking at #856 but I don't think this was explicitly mentioned, maybe obliquely in §1.2.1.2. However, I think the rationale for requiring @justingrant As the originator of Duration.round what do you think? |
Good catch @cjtenny! The underlying goal of throwing here is to prevent unintended no-ops via
So here's what I'd expect: d = Temporal.Duration.from({ days: 1, minutes: 90 });
d.round({ largestUnit: 'auto', smallestUnit: 'nanoseconds' }); // => OK
d.round({ largestUnit: 'auto' }); // => OK
d.round({ smallestUnit: 'nanoseconds' }); // => OK
d.round({}); // => throws
d.round(); // => throws I think (not 100% sure though) that the cases above and their expected results match the docs, but not the polyfill nor the spec. @cjtenny and @ptomato - does that match what you see? The reason why BTW, this line in the docs is the critical one:
My intent was that the default of |
My point above was that this is true for the other types, but not for Duration. |
Sorry, you're correct-- I didn't understand your point above, but now I do. As you noted there are (unusual) cases where the non-largest unit is unbalanced and the user's goal would be to do balancing on intra-duration units without growing the duration beyond its current largest unit. AFAIK this is an unusual use case that's much less common than this being a bug where options were unintentionally missing or where the caller expected some default rounding (e.g. to the nearest second) that won't actually happen. So I'd still support the behavior in the docs where |
Fair enough, that makes sense. |
The PR I added makes |
and they might be semantically important :/
The specification text defines but doesn't use either of
smallestUnitPresent
orlargestUnitPresent
.In the polyfill and docs, it is specified that at least one of the two must be present or a
RangeError
will be thrown.There is currently a discrepancy between the polyfill, docs, and spec text in that the following snippet throws. The polyfill throws, the docs say it shouldn't throw but that one is required, and the spec doesn't say that either is required.
Obviously,
largestUnit
is provided. Also, according to spec text, this shouldn't throw (there is no check that both are present or specification to throw) - the spec would use default values for bothsmallestUnit
andlargestUnit
if passed an empty options bag, but would throw if not passed any options.What should we do here?
Were the spec text to be updated to throw if one were present, N.B. that
ToLargestTemporalUnit
doesn't distinguish between'auto'
being provided andauto'
being the default, so the unused computation oflargestUnitPresent
is still incorrect.Does it make sense to require non-default for
largestUnit
but not forsmallestUnit
? (i.e. the current polyfill state; the default of'nanoseconds'
works: the snippetTemporal.Duration.from({days: 1}).round({smallestUnit: 'nanoseconds'});
does not throw). My belief is that the version espoused in the docs is the best version, which would require a small spec text change.There are also some errors in the spec text that should be fixed at the same time:
ToSmallestTemporalDurationUnit
is called with the wrong # of arguments; should probably be(options, undefined, « »)
ToLargestTemporalUnit
is called with the wrong # of arguments; should probably be(options, « », undefined)
The text was updated successfully, but these errors were encountered: