Test balancing in PlainDate#{add,subtract}.

This commit is contained in:
Ms2ger 2022-01-24 10:53:11 +01:00 committed by Rick Waldron
parent 3fd429b231
commit ef0b1507fc
2 changed files with 58 additions and 0 deletions

View File

@ -0,0 +1,29 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dateadd
description: Durations with units smaller than days are balanced
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const date = new Temporal.PlainDate(1976, 11, 18);
// lower units that don't balance up to a day
TemporalHelpers.assertPlainDate(date.add({ hours: 1 }), 1976, 11, "M11", 18);
TemporalHelpers.assertPlainDate(date.add({ minutes: 1 }), 1976, 11, "M11", 18);
TemporalHelpers.assertPlainDate(date.add({ seconds: 1 }), 1976, 11, "M11", 18);
TemporalHelpers.assertPlainDate(date.add({ milliseconds: 1 }), 1976, 11, "M11", 18);
TemporalHelpers.assertPlainDate(date.add({ microseconds: 1 }), 1976, 11, "M11", 18);
TemporalHelpers.assertPlainDate(date.add({ nanoseconds: 1 }), 1976, 11, "M11", 18);
// lower units that balance up to a day or more
TemporalHelpers.assertPlainDate(date.add({ hours: 24 }), 1976, 11, "M11", 19);
TemporalHelpers.assertPlainDate(date.add({ hours: 36 }), 1976, 11, "M11", 19);
TemporalHelpers.assertPlainDate(date.add({ hours: 48 }), 1976, 11, "M11", 20);
TemporalHelpers.assertPlainDate(date.add({ minutes: 1440 }), 1976, 11, "M11", 19);
TemporalHelpers.assertPlainDate(date.add({ seconds: 86400 }), 1976, 11, "M11", 19);
TemporalHelpers.assertPlainDate(date.add({ milliseconds: 86400_000 }), 1976, 11, "M11", 19);
TemporalHelpers.assertPlainDate(date.add({ microseconds: 86400_000_000 }), 1976, 11, "M11", 19);
TemporalHelpers.assertPlainDate(date.add({ nanoseconds: 86400_000_000_000 }), 1976, 11, "M11", 19);

View File

@ -0,0 +1,29 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dateadd
description: Durations with units smaller than days are balanced
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const date = new Temporal.PlainDate(1976, 11, 18);
// lower units that don't balance up to a day
TemporalHelpers.assertPlainDate(date.subtract({ hours: 1 }), 1976, 11, "M11", 18);
TemporalHelpers.assertPlainDate(date.subtract({ minutes: 1 }), 1976, 11, "M11", 18);
TemporalHelpers.assertPlainDate(date.subtract({ seconds: 1 }), 1976, 11, "M11", 18);
TemporalHelpers.assertPlainDate(date.subtract({ milliseconds: 1 }), 1976, 11, "M11", 18);
TemporalHelpers.assertPlainDate(date.subtract({ microseconds: 1 }), 1976, 11, "M11", 18);
TemporalHelpers.assertPlainDate(date.subtract({ nanoseconds: 1 }), 1976, 11, "M11", 18);
// lower units that balance up to a day or more
TemporalHelpers.assertPlainDate(date.subtract({ hours: 24 }), 1976, 11, "M11", 17);
TemporalHelpers.assertPlainDate(date.subtract({ hours: 36 }), 1976, 11, "M11", 17);
TemporalHelpers.assertPlainDate(date.subtract({ hours: 48 }), 1976, 11, "M11", 16);
TemporalHelpers.assertPlainDate(date.subtract({ minutes: 1440 }), 1976, 11, "M11", 17);
TemporalHelpers.assertPlainDate(date.subtract({ seconds: 86400 }), 1976, 11, "M11", 17);
TemporalHelpers.assertPlainDate(date.subtract({ milliseconds: 86400_000 }), 1976, 11, "M11", 17);
TemporalHelpers.assertPlainDate(date.subtract({ microseconds: 86400_000_000 }), 1976, 11, "M11", 17);
TemporalHelpers.assertPlainDate(date.subtract({ nanoseconds: 86400_000_000_000 }), 1976, 11, "M11", 17);