summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/Temporal/Calendar/prototype/dateAdd/basic.js
blob: 2424570c7470f17ffa1b48e9448340f6f0a11b9f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally
// Copyright (C) 2021 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: Basic tests for dateAdd().
includes: [temporalHelpers.js]
features: [Temporal]
---*/

const iso = Temporal.Calendar.from("iso8601");
const date = Temporal.PlainDate.from("1994-11-06");
const positiveDuration = Temporal.Duration.from({ months: 1, weeks: 1 });
const negativeDuration = Temporal.Duration.from({ months: -1, weeks: -1 });

TemporalHelpers.assertPlainDate(
  iso.dateAdd(Temporal.PlainDateTime.from("1994-11-06T08:15:30"), positiveDuration, {}),
  1994, 12, "M12", 13, "date: PlainDateTime");

TemporalHelpers.assertPlainDate(
  iso.dateAdd({ year: 1994, month: 11, day: 6 }, positiveDuration, {}),
  1994, 12, "M12", 13, "date: property bag");

TemporalHelpers.assertPlainDate(
  iso.dateAdd("1994-11-06", positiveDuration, {}),
  1994, 12, "M12", 13, "date: string");

assert.throws(TypeError, () => iso.dateAdd({ month: 11 }, positiveDuration, {}), "date: missing property");

TemporalHelpers.assertPlainDate(
  iso.dateAdd(date, { months: 1, weeks: 1 }, {}),
  1994, 12, "M12", 13, "duration: property bag");

TemporalHelpers.assertPlainDate(
  iso.dateAdd(date, "P1M1W", {}),
  1994, 12, "M12", 13, "duration: string");

assert.throws(TypeError, () => iso.dateAdd(date, { month: 1 }, {}), "duration: missing property");

TemporalHelpers.assertPlainDate(
  iso.dateAdd(Temporal.PlainDateTime.from("1994-11-06T08:15:30"), negativeDuration, {}),
  1994, 9, "M09", 29, "date: PlainDateTime, negative duration");

TemporalHelpers.assertPlainDate(
  iso.dateAdd({ year: 1994, month: 11, day: 6 }, negativeDuration, {}),
  1994, 9, "M09", 29, "date: property bag, negative duration");

TemporalHelpers.assertPlainDate(
  iso.dateAdd("1994-11-06", negativeDuration, {}),
  1994, 9, "M09", 29, "date: string, negative duration");

reportCompare(0, 0);