Add tests for Temporal.Calendar.prototype.(year|month*|day)

This commit is contained in:
Frank Tang 2021-07-17 02:02:40 -07:00 committed by Rick Waldron
parent 750ec2b581
commit 932c931a70
5 changed files with 113 additions and 0 deletions

View File

@ -0,0 +1,22 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.day
description: Temporal.Calendar.prototype.day will take different kind of objects.
and return the value of the day.
info: |
1. Let calendar be the this value.
2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]).
3. Assert: calendar.[[Identifier]] is "iso8601".
4. If Type(temporalDateLike) is not Object or temporalDateLike does not have an [[InitializedTemporalDate]] or [[InitializedTemporalMonthDay]] internal slot, then
a. Set temporalDateLike to ? ToTemporalDate(temporalDateLike).
5. Return ! ISODay(temporalDateLike).
features: [Temporal]
---*/
let cal = new Temporal.Calendar("iso8601");
assert.sameValue(15, cal.day(new Temporal.PlainDate(2021, 7, 15)));
assert.sameValue(23, cal.day(new Temporal.PlainDateTime(1997, 8, 23, 5, 30, 13)));
assert.sameValue(6, cal.day(new Temporal.PlainMonthDay(2, 6)));
assert.sameValue(18, cal.day("2019-03-18"));

View File

@ -0,0 +1,23 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.monthcode
description: Temporal.Calendar.prototype.monthCode will take different kind of object and return
the value of the monthCode.
info: |
1. Let calendar be the this value.
2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]).
3. Assert: calendar.[[Identifier]] is "iso8601".
4. If Type(temporalDateLike) is not Object or temporalDateLike does not have an [[InitializedTemporalDate]], [[InitializedTemporalMonthDay]], or [[InitializedTemporalYearMonth]] internal slot, then
a. Set temporalDateLike to ? ToTemporalDate(temporalDateLike).
5. Return ! ISOMonthCode(temporalDateLike).
features: [Temporal]
---*/
let cal = new Temporal.Calendar("iso8601");
assert.sameValue("M07", cal.monthCode(new Temporal.PlainDate(2021, 7, 15)));
assert.sameValue("M08", cal.monthCode(new Temporal.PlainDateTime(1997, 8, 23, 5, 30, 13)));
assert.sameValue("M06", cal.monthCode(new Temporal.PlainYearMonth(1999, 6)));
assert.sameValue("M02", cal.monthCode(new Temporal.PlainMonthDay(2, 6)));
assert.sameValue("M03", cal.monthCode("2019-03-15"));

View File

@ -0,0 +1,24 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.month
description: Temporal.Calendar.prototype.month will take different kind of object and
return month value.
info: |
1. Let calendar be the this value.
2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]).
3. Assert: calendar.[[Identifier]] is "iso8601".
4. If Type(temporalDateLike) is Object and temporalDateLike has an [[InitializedTemporalMonthDay]] internal slot, then
a. Throw a TypeError exception.
5. If Type(temporalDateLike) is not Object or temporalDateLike does not have an [[InitializedTemporalDate]] or [[InitializedTemporalYearMonth]] internal slot, then
a. Set temporalDateLike to ? ToTemporalDate(temporalDateLike).
6. Return ! ISOMonth(temporalDateLike).
features: [Temporal]
---*/
let cal = new Temporal.Calendar("iso8601");
assert.sameValue(7, cal.month(new Temporal.PlainDate(2021, 7, 15)));
assert.sameValue(8, cal.month(new Temporal.PlainDateTime(1997, 8, 23, 5, 30, 13)));
assert.sameValue(6, cal.month(new Temporal.PlainYearMonth(1999, 6)));
assert.sameValue(3, cal.month("2019-03-15"));

View File

@ -0,0 +1,22 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.month
description: Temporal.Calendar.prototype.month will throws TypeError while the input object
has an [[InitializedTemporalMonthDay]] internal slot.
info: |
1. Let calendar be the this value.
2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]).
3. Assert: calendar.[[Identifier]] is "iso8601".
4. If Type(temporalDateLike) is Object and temporalDateLike has an [[InitializedTemporalMonthDay]] internal slot, then
a. Throw a TypeError exception.
5. If Type(temporalDateLike) is not Object or temporalDateLike does not have an [[InitializedTemporalDate]] or [[InitializedTemporalYearMonth]] internal slot, then
a. Set temporalDateLike to ? ToTemporalDate(temporalDateLike).
6. Return ! ISOMonth(temporalDateLike).
features: [Temporal]
---*/
let cal = new Temporal.Calendar("iso8601");
assert.throws(TypeError, () => cal.month(new Temporal.PlainMonthDay(3, 16)),
"invalid_argument");

View File

@ -0,0 +1,22 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.year
description: Temporal.Calendar.prototype.year will take different kind of object and return
the value of the year.
info: |
1. Let calendar be the this value.
2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]).
3. Assert: calendar.[[Identifier]] is "iso8601".
4. If Type(temporalDateLike) is not Object or temporalDateLike does not have an [[InitializedTemporalDate]] or [[InitializedTemporalYearMonth]] internal slot, then
a. Set temporalDateLike to ? ToTemporalDate(temporalDateLike).
5. Return ! ISOYear(temporalDateLike).
features: [Temporal]
---*/
let cal = new Temporal.Calendar("iso8601");
assert.sameValue(2021, cal.year(new Temporal.PlainDate(2021, 7, 15)));
assert.sameValue(1997, cal.year(new Temporal.PlainDateTime(1997, 8, 23, 5, 30, 13)));
assert.sameValue(1999, cal.year(new Temporal.PlainYearMonth(1999, 6)));
assert.sameValue(2019, cal.year("2019-03-15"));