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

Throw if difference() is out-of-order & stop limiting Time.prototype.difference to 12 hours #667

Merged
merged 2 commits into from
Jun 15, 2020

Conversation

justingrant
Copy link
Collaborator

This PR:
a) Changes difference() to throw if other is larger than this, which prevents users from accidentally treating invalid negative differences as valid positive differences. Fixes #663.
b) Because difference() is now unidirectional, it doesn't make sense to restrict Time.prototype.difference to 12 hours max. Fixes #597. Ideally (a) and (b) would be separate PRs, but the implementation was hard to split so I combined into one PR.

Although (a) will likely be considered non-ideal ergonomics, the exception will likely be helpful to generate feedback from polyfill early adopters about what they want the behavior to be and what they think is the best long-term option, e.g.:

  • option 1 - previous behavior: difference() returns an absolute value
  • option 2 - behavior in this commit: throw if other is larger
  • option 3 - negative durations (No negative durations? #558)

This PR updates tests to make it easy to choose any of the three options in a later release. The (few) tests for option 1 are commented out but still checked in to make it easy to choose option 1 later. The rest of test changes were reversing arguments which are compatible with all three options. This means that choosing either (1) or (3) later will break few existing tests.

@codecov
Copy link

codecov bot commented Jun 12, 2020

Codecov Report

Merging #667 into main will decrease coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #667      +/-   ##
==========================================
- Coverage   94.43%   94.42%   -0.01%     
==========================================
  Files          17       17              
  Lines        4760     4757       -3     
  Branches      749      752       +3     
==========================================
- Hits         4495     4492       -3     
  Misses        262      262              
  Partials        3        3              
Flag Coverage Δ
#test262 52.86% <0.00%> (+0.04%) ⬆️
#tests 89.33% <95.65%> (-0.03%) ⬇️
Impacted Files Coverage Δ
polyfill/lib/absolute.mjs 100.00% <100.00%> (ø)
polyfill/lib/date.mjs 93.45% <100.00%> (+0.02%) ⬆️
polyfill/lib/datetime.mjs 93.56% <100.00%> (+<0.01%) ⬆️
polyfill/lib/time.mjs 99.29% <100.00%> (-0.02%) ⬇️
polyfill/lib/yearmonth.mjs 97.82% <100.00%> (+<0.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c4b7b3e...d8051d4. Read the comment docs.

@justingrant justingrant force-pushed the difference-out-of-order-exception branch from 2c9b046 to 6ff4c9a Compare June 12, 2020 11:49
Copy link
Collaborator

@ptomato ptomato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, I do think the "returns the same duration regardless of start time" test needs to be rewritten though. In fact I'd make separate tests that test specifically that the exception is thrown when the arguments are reversed.

polyfill/lib/time.mjs Outdated Show resolved Hide resolved
polyfill/test/time.mjs Show resolved Hide resolved
spec/absolute.html Outdated Show resolved Hide resolved
@justingrant
Copy link
Collaborator Author

@ptomato - Would you prefer me to merge or rebase+force-push to resolve the conflicts with your latest calendar checkins? Also I think I've resolved all your review comments except the one waiting for a reply.

@ptomato
Copy link
Collaborator

ptomato commented Jun 13, 2020

Rebase and force push is what I usually do!

@justingrant justingrant force-pushed the difference-out-of-order-exception branch from c589c47 to 8984f3a Compare June 13, 2020 21:34
Fixes tc39#663. Changes `difference()` methods to throw if `other`is
larger than `this`. Goal is encourage feedback about long-term solution:
option 1 - previous behavior: `difference()` returns an absolute value
option 2 - behavior in this commit: throw if other is larger
option 3 - negative durations (tc39#558)

Tests are updated to make it easy to choose any of the three options.
Only a few tests were functionally changed (e.g. to add throws() tests).
The rest of test changes were reversing arguments so that choosing any
of the options later will break relatively few tests.

Because `difference` is now unidirectional, it doesn't make sense to
restrict `Time.prototype.difference` to 12 hours max. Fixes tc39#597.
@justingrant justingrant force-pushed the difference-out-of-order-exception branch from 8984f3a to 9bec1d4 Compare June 13, 2020 21:38
Copy link
Collaborator

@ptomato ptomato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just one forgotten comment. I will see if I can update the branch to fix it myself, and then merge it.

polyfill/test/datetime.mjs Outdated Show resolved Hide resolved
@ptomato ptomato merged commit d84653e into tc39:main Jun 15, 2020
This was referenced Aug 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants