-
Notifications
You must be signed in to change notification settings - Fork 155
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
Throw if difference()
is out-of-order & stop limiting Time.prototype.difference
to 12 hours
#667
Conversation
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
2c9b046
to
6ff4c9a
Compare
There was a problem hiding this 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.
@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. |
Rebase and force push is what I usually do! |
c589c47
to
8984f3a
Compare
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.
8984f3a
to
9bec1d4
Compare
There was a problem hiding this 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.
This PR:
a) Changes
difference()
to throw ifother
is larger thanthis
, 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 restrictTime.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.:
difference()
returns an absolute valueThis 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.