-
Notifications
You must be signed in to change notification settings - Fork 516
[Temporal] Add coverage for different rounding increments #4793
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| // Copyright (C) 2025 Igalia, S.L. All rights reserved. | ||
| // This code is governed by the BSD license found in the LICENSE file. | ||
|
|
||
| /*--- | ||
| esid: sec-temporal.plaintime.prototype.round | ||
| description: Rounding increment should properly divide the relevant time unit | ||
| features: [Temporal] | ||
| ---*/ | ||
|
|
||
| const t = new Temporal.PlainTime(14, 23, 30, 123, 456, 789); | ||
|
|
||
| [1, 2, 3, 4, 6, 8, 12].forEach((roundingIncrement) => { | ||
| assert.sameValue( | ||
| t.round({ smallestUnit: "hour", roundingIncrement }) instanceof Temporal.PlainDateTime, | ||
|
||
| true, | ||
| `valid hour increments divide into 24 (rounding increment = ${roundingIncrement})`); | ||
| }); | ||
|
|
||
| ["minute", "second"].forEach((smallestUnit) => { | ||
| [1, 2, 3, 4, 5, 6, 10, 12, 15, 20, 30].forEach((roundingIncrement) => { | ||
| assert.sameValue( | ||
| t.round({ smallestUnit, roundingIncrement }) instanceof Temporal.PlainDateTime, | ||
| true, | ||
| `valid ${smallestUnit} increments divide into 60 (rounding increment = ${roundingIncrement})` | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| ["millisecond", "microsecond", "nanosecond"].forEach((smallestUnit) => { | ||
| [1, 2, 4, 5, 8, 10, 20, 25, 40, 50, 100, 125, 200, 250, 500].forEach((roundingIncrement) => { | ||
| assert.sameValue( | ||
| t.round({ smallestUnit, roundingIncrement }) instanceof Temporal.PlainDateTime, | ||
| true, | ||
| `valid ${smallestUnit} increments divide into 1000 (rounding increment = ${roundingIncrement})`); | ||
| }); | ||
| }); | ||
|
|
||
| const nextIncrements = { | ||
| "hour": 24, | ||
| "minute": 60, | ||
| "second": 60, | ||
| "millisecond": 1000, | ||
| "microsecond": 1000, | ||
| "nanosecond": 1000 | ||
| }; | ||
|
|
||
| Object.entries(nextIncrements).forEach(([unit, next]) => { | ||
| assert.throws( | ||
| RangeError, | ||
| () => t.round({ smallestUnit: unit, roundingIncrement: next }), | ||
| `throws on increments that are equal to the next highest (unit = ${unit}, increment = ${next})` | ||
| ); | ||
| }); | ||
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.
Nit: please format these consistently between files
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 in 99c46d3