Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,26 @@ description: >
features: [Temporal]
---*/

// Largest temporal unit is "second".
const duration = Temporal.Duration.from({seconds: Number.MAX_SAFE_INTEGER});
const maxSec = Number.MAX_SAFE_INTEGER;
const maxMs = 9_007_199_254_740_991_487;
const maxUs = 9_007_199_254_740_991_475_711;
const maxNs = 9_007_199_254_740_991_463_129_087;

const durations = [
Temporal.Duration.from({seconds: maxSec}),
Temporal.Duration.from({milliseconds: maxMs}),
Temporal.Duration.from({microseconds: maxUs}),
Temporal.Duration.from({nanoseconds: maxNs}),
Temporal.Duration.from({seconds: -maxSec}),
Temporal.Duration.from({milliseconds: -maxMs}),
Temporal.Duration.from({microseconds: -maxUs}),
Temporal.Duration.from({nanoseconds: -maxNs}),
]

for (let duration of durations) {
assert.throws(RangeError, () => {
duration.add(duration);
});
}


assert.throws(RangeError, () => {
duration.add(duration);
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,44 @@ description: >
features: [Temporal]
---*/

const d = new Temporal.Duration(0, 0, 0, 0, 0, 0, /* s = */ Number.MAX_SAFE_INTEGER, 0, 0, /* ns = */ 999_999_999);
assert.throws(RangeError, () => d.round({
/*
const maxMs = 9_007_199_254_740_991_487;
const maxUs = 9_007_199_254_740_991_475_711;
const maxNs = 9_007_199_254_740_991_463_129_087;
*/

const ms = new Temporal.Duration(0, 0, 0, 0, 0, 0, /* s = */ Number.MAX_SAFE_INTEGER, /* ms = */ 488, 0, 0);
assert.throws(RangeError, () => ms.round({
largestUnit: "nanoseconds",
roundingIncrement: 1,
}), "nanoseconds component after balancing as a float64-representable integer is out of range (maximum milliseconds)");

const us = new Temporal.Duration(0, 0, 0, 0, 0, 0, /* s = */ Number.MAX_SAFE_INTEGER, 0, /* us = */ 475_712, 0);
assert.throws(RangeError, () => ms.round({
largestUnit: "nanoseconds",
roundingIncrement: 1,
}), "nanoseconds component after balancing as a float64-representable integer is out of range (maximum microseconds)");

const ns = new Temporal.Duration(0, 0, 0, 0, 0, 0, /* s = */ Number.MAX_SAFE_INTEGER, 0, 0, /* ns = */ 463_129_088);
assert.throws(RangeError, () => ns.round({
largestUnit: "nanoseconds",
roundingIncrement: 1,
}), "nanoseconds component after balancing as a float64-representable integer is out of range (maximum nanoseconds)");

const msMin = new Temporal.Duration(0, 0, 0, 0, 0, 0, /* s = */ -Number.MAX_SAFE_INTEGER, /* ms = */ -487, 0, 0);
assert.throws(RangeError, () => msMin.round({
largestUnit: "nanoseconds",
roundingIncrement: 1,
}), "nanoseconds component after balancing as a float64-representable integer is out of range (minimum milliseconds)");

const usMin = new Temporal.Duration(0, 0, 0, 0, 0, 0, /* s = */ -Number.MAX_SAFE_INTEGER, 0, /* us = */ -475_711, 0);
assert.throws(RangeError, () => usMin.round({
largestUnit: "nanoseconds",
roundingIncrement: 1,
}), "nanoseconds component after balancing as a float64-representable integer is out of range (minimum microseconds)");

const nsMin = new Temporal.Duration(0, 0, 0, 0, 0, 0, /* s = */ -Number.MAX_SAFE_INTEGER, 0, 0, /* ns = */ -463_129_088);
assert.throws(RangeError, () => nsMin.round({
largestUnit: "nanoseconds",
roundingIncrement: 1,
}), "nanoseconds component after balancing as a float64-representable integer is out of range");
}), "nanoseconds component after balancing as a float64-representable integer is out of range (minimum nanoseconds)");
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,20 @@ description: >
features: [Temporal]
---*/

var duration = Temporal.Duration.from({
seconds: Number.MAX_SAFE_INTEGER,
});
const maxMs = 9_007_199_254_740_991_487;
const maxUs = 9_007_199_254_740_991_475_711;
const maxNs = 9_007_199_254_740_991_463_129_087;

const durations = [
Temporal.Duration.from({ seconds: Number.MAX_SAFE_INTEGER }),
Temporal.Duration.from({ milliseconds: maxMs }),
Temporal.Duration.from({ microseconds: maxUs }),
Temporal.Duration.from({ nanoseconds: maxNs }),
Temporal.Duration.from({ seconds: -Number.MAX_SAFE_INTEGER }),
Temporal.Duration.from({ milliseconds: -maxMs }),
Temporal.Duration.from({ microseconds: -maxUs }),
Temporal.Duration.from({ nanoseconds: -maxNs }),
];

var zonedDateTime = new Temporal.ZonedDateTime(0n, "UTC");

Expand All @@ -20,4 +31,6 @@ var options = {
relativeTo: zonedDateTime,
};

assert.throws(RangeError, () => duration.round(options));
for (let duration of durations) {
assert.throws(RangeError, () => duration.round(options));
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,24 @@ description: >
features: [Temporal]
---*/

// Largest temporal unit is "second".
const duration1 = Temporal.Duration.from({seconds: Number.MAX_SAFE_INTEGER});
const duration2 = Temporal.Duration.from({seconds: -Number.MAX_SAFE_INTEGER});
const maxSec = Number.MAX_SAFE_INTEGER;
const maxMs = 9_007_199_254_740_991_487;
const maxUs = 9_007_199_254_740_991_475_711;
const maxNs = 9_007_199_254_740_991_463_129_087;

assert.throws(RangeError, () => {
duration1.subtract(duration2);
});
const durations = [
Temporal.Duration.from({seconds: maxSec}),
Temporal.Duration.from({milliseconds: maxMs}),
Temporal.Duration.from({microseconds: maxUs}),
Temporal.Duration.from({nanoseconds: maxNs}),
Temporal.Duration.from({seconds: -maxSec}),
Temporal.Duration.from({milliseconds: -maxMs}),
Temporal.Duration.from({microseconds: -maxUs}),
Temporal.Duration.from({nanoseconds: -maxNs}),
];

for (let duration of durations) {
assert.throws(RangeError, () => {
duration.subtract(duration.negated());
}, `subtracting the negation of a large duration from the duration is out of bounds: ${duration}`);
}