-
Notifications
You must be signed in to change notification settings - Fork 464
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
Temporal: Add test for balancing up to weeks when year/month are present #4305
Open
catamorphism
wants to merge
4
commits into
tc39:main
Choose a base branch
from
catamorphism:temporal-issue-2813
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d140b70
Temporal: Add test for balancing up to weeks when year/month are present
catamorphism dda3f4c
Update test/built-ins/Temporal/Duration/prototype/round/balances-up-t…
catamorphism d6bdfbd
Update test/built-ins/Temporal/Duration/prototype/round/balances-up-t…
catamorphism ef93787
Factored out relativeTo and added test for rounding 29 days up to weeks
catamorphism File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
test/built-ins/Temporal/Duration/prototype/round/balances-up-to-weeks.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright (C) 2024 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.duration.prototype.round | ||
description: Rounds up to weeks correctly when years and months are present. | ||
includes: [temporalHelpers.js] | ||
features: [Temporal] | ||
---*/ | ||
|
||
const oneMonthOneDay = new Temporal.Duration(0, 1, 0, 1, 0, 0, 0, 0, 0, 0); | ||
const oneYearOneMonthOneDay = new Temporal.Duration(1, 1, 0, 1, 0, 0, 0, 0, 0, 0); | ||
const severalWeeksInDays = new Temporal.Duration(0, 0, 0, 29, 0, 0, 0, 0, 0, 0); | ||
const relativeTo = new Temporal.PlainDate(2024, 1, 1); | ||
|
||
// largestUnit must be included | ||
assert.throws(RangeError, () => oneMonthOneDay.round({ | ||
relativeTo, | ||
smallestUnit: 'weeks', | ||
roundingIncrement: 99, | ||
roundingMode: 'ceil' | ||
})); | ||
|
||
TemporalHelpers.assertDuration(oneMonthOneDay.round({ | ||
relativeTo, | ||
largestUnit: 'weeks', | ||
smallestUnit: 'weeks', | ||
roundingIncrement: 99, | ||
roundingMode: 'ceil' | ||
}), 0, 0, 99, 0, 0, 0, 0, 0, 0, 0); | ||
|
||
TemporalHelpers.assertDuration(oneMonthOneDay.round({ | ||
relativeTo, | ||
largestUnit: 'weeks', | ||
smallestUnit: 'weeks', | ||
roundingIncrement: 6, | ||
roundingMode: 'ceil' | ||
}), 0, 0, 6, 0, 0, 0, 0, 0, 0, 0); | ||
|
||
TemporalHelpers.assertDuration(oneYearOneMonthOneDay.round({ | ||
relativeTo, | ||
largestUnit: 'weeks', | ||
smallestUnit: 'weeks', | ||
roundingIncrement: 99, | ||
roundingMode: 'ceil' | ||
}), 0, 0, 99, 0, 0, 0, 0, 0, 0, 0); | ||
|
||
TemporalHelpers.assertDuration(oneYearOneMonthOneDay.round({ | ||
relativeTo, | ||
largestUnit: 'weeks', | ||
smallestUnit: 'weeks', | ||
roundingIncrement: 57, | ||
roundingMode: 'ceil' | ||
}), 0, 0, 57, 0, 0, 0, 0, 0, 0, 0); | ||
|
||
TemporalHelpers.assertDuration(severalWeeksInDays.round({ | ||
relativeTo, | ||
largestUnit: 'weeks', | ||
smallestUnit: 'weeks', | ||
roundingIncrement: 5, | ||
roundingMode: 'ceil' | ||
}), 0, 0, 5, 0, 0, 0, 0, 0, 0, 0); | ||
|
||
TemporalHelpers.assertDuration(severalWeeksInDays.round({ | ||
relativeTo, | ||
largestUnit: 'weeks', | ||
smallestUnit: 'weeks', | ||
roundingIncrement: 8, | ||
roundingMode: 'ceil' | ||
}), 0, 0, 8, 0, 0, 0, 0, 0, 0, 0); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I'd suggest something like
and using that in the options bags throughout.
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.
Also, I've been looking at the existing tests in
round/
and I think we might not have coverage of rounding a duration with only days up to weeks. So maybe add something like(I might have missed it if we already had coverage of this, though! There are a lot of tests in this folder)
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.
Done and done.