split into different add files

This commit is contained in:
Frank Tang 2021-08-04 13:38:05 -07:00 committed by Rick Waldron
parent f772019855
commit df42e9a19b
12 changed files with 321 additions and 83 deletions

View File

@ -0,0 +1,36 @@
// 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.dateadd
description: Temporal.Calendar.prototype.dateAdd add duration with days and calculate correctly..
info: |
8. Let result be ? AddISODate(date.[[ISOYear]], date.[[ISOMonth]], date.[[ISODay]], duration.[[Years]], duration.[[Months]], duration.[[Weeks]], duration.[[Days]], overflow).
features: [Temporal]
includes: [temporalHelpers.js]
---*/
let cal = new Temporal.Calendar("iso8601");
let p10d = new Temporal.Duration(0,0,0,10);
TemporalHelpers.assertPlainDate(
cal.dateAdd("2021-07-16", p10d), 2021, 7, "M07", 26,
"add 10 days and result into the same month");
TemporalHelpers.assertPlainDate(
cal.dateAdd("2021-07-26", p10d), 2021, 8, "M08", 5,
"add 10 days and result into next month");
TemporalHelpers.assertPlainDate(
cal.dateAdd("2021-12-26", p10d), 2022, 1, "M01", 5,
"add 10 days and result into next year");
TemporalHelpers.assertPlainDate(
cal.dateAdd("2020-02-26", p10d), 2020, 3, "M03", 7,
"add 10 days from a leap year in Feb and result into March");
TemporalHelpers.assertPlainDate(
cal.dateAdd("2021-02-26", p10d), 2021, 3, "M03", 8,
"add 10 days from a non leap year in Feb and result into March");
TemporalHelpers.assertPlainDate(
cal.dateAdd("2020-02-19", p10d), 2020, 2, "M02", 29,
"add 10 days from a leap year in Feb 19 and result into Feb 29");
TemporalHelpers.assertPlainDate(
cal.dateAdd("2021-02-19", p10d), 2021, 3, "M03", 1,
"add 10 days from a non leap year in Feb 19 and result into March 1");

View File

@ -0,0 +1,36 @@
// 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.dateadd
description: Temporal.Calendar.prototype.dateAdd add duration with months and weeks and calculate correctly.
info: |
8. Let result be ? AddISODate(date.[[ISOYear]], date.[[ISOMonth]], date.[[ISODay]], duration.[[Years]], duration.[[Months]], duration.[[Weeks]], duration.[[Days]], overflow).
features: [Temporal]
includes: [temporalHelpers.js]
---*/
let cal = new Temporal.Calendar("iso8601");
let p2m3w = new Temporal.Duration(0,2,3);
TemporalHelpers.assertPlainDate(
cal.dateAdd("2020-02-29", p2m3w), 2020, 5, "M05", 20,
"add two months 3 weeks from Feb 29 of a leap year");
TemporalHelpers.assertPlainDate(
cal.dateAdd("2020-02-28", p2m3w), 2020, 5, "M05", 19,
"add two months 3 weeks from Feb 28 of a leap year");
TemporalHelpers.assertPlainDate(
cal.dateAdd("2021-02-28", p2m3w), 2021, 5, "M05", 19,
"add two months 3 weeks from Feb 28 of a non leap year");
TemporalHelpers.assertPlainDate(
cal.dateAdd("2020-12-28", p2m3w), 2021, 3, "M03", 21,
"add two months 3 weeks from end of year to non leap year");
TemporalHelpers.assertPlainDate(
cal.dateAdd("2019-12-28", p2m3w), 2020, 3, "M03", 20,
"add two months 3 weeks from end of year to leap year");
TemporalHelpers.assertPlainDate(
cal.dateAdd("2019-10-28", p2m3w), 2020, 1, "M01", 18,
"add two months 3 weeks and cause roll into a new year");
TemporalHelpers.assertPlainDate(
cal.dateAdd("2019-10-31", p2m3w), 2020, 1, "M01", 21,
"add two months 3 weeks and cause roll into a new year");

View File

@ -0,0 +1,33 @@
// 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.dateadd
description: Temporal.Calendar.prototype.dateAdd add duration with months and calculate correctly
info: |
8. Let result be ? AddISODate(date.[[ISOYear]], date.[[ISOMonth]], date.[[ISODay]], duration.[[Years]], duration.[[Months]], duration.[[Weeks]], duration.[[Days]], overflow).
features: [Temporal]
includes: [temporalHelpers.js]
---*/
let cal = new Temporal.Calendar("iso8601");
let p5m = new Temporal.Duration(0, 5);
TemporalHelpers.assertPlainDate(
cal.dateAdd("2021-07-16", p5m), 2021, 12, "M12", 16,
"add five months and result in the same year");
TemporalHelpers.assertPlainDate(
cal.dateAdd("2021-08-16", p5m), 2022, 1, "M01", 16,
"add five months and result in the next year");
TemporalHelpers.assertPlainDate(
cal.dateAdd("2021-10-31", p5m), 2022, 3, "M03", 31,
"add five months and result in the next year in end of month");
TemporalHelpers.assertPlainDate(
cal.dateAdd("2019-10-01", p5m), 2020, 3, "M03", 1,
"add five months and result in the next year in end of month on leap year");
TemporalHelpers.assertPlainDate(
cal.dateAdd("2021-09-30", p5m), 2022, 2, "M02", 28,
"add five months and result in the nexdt year and constrain to Feb 28");
TemporalHelpers.assertPlainDate(
cal.dateAdd("2019-09-30", p5m), 2020, 2, "M02", 29,
"add five months and result in the nexdt year and constrain to Feb 29 on leap year");

View File

@ -0,0 +1,26 @@
// 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.dateadd
description: Temporal.Calendar.prototype.dateAdd add duration with weeks and days and calculate correctly.
info: |
8. Let result be ? AddISODate(date.[[ISOYear]], date.[[ISOMonth]], date.[[ISODay]], duration.[[Years]], duration.[[Months]], duration.[[Weeks]], duration.[[Days]], overflow).
features: [Temporal]
includes: [temporalHelpers.js]
---*/
let cal = new Temporal.Calendar("iso8601");
let p2w3d = new Temporal.Duration(0,0,2,3);
TemporalHelpers.assertPlainDate(
cal.dateAdd("2020-02-29", p2w3d), 2020, 3, "M03", 17,
"add 2 weeks and 3 days (17 days) from Feb 29 in a leap year and cause rolling into March");
TemporalHelpers.assertPlainDate(
cal.dateAdd("2021-02-28", p2w3d), 2021, 3, "M03", 17,
"add 2 weeks and 3 days (17 days) from Feb and cause rolling into March in a non leap year");
TemporalHelpers.assertPlainDate(
cal.dateAdd("2020-02-28", p2w3d), 2020, 3, "M03", 16,
"add 2 weeks and 3 days (17 days) from Feb and cause rolling into March in a leap year");
TemporalHelpers.assertPlainDate(
cal.dateAdd("2020-12-28", p2w3d), 2021, 1, "M01", 14,
"add 2 weeks and 3 days (17 days) and cause rolling into a new year");

View File

@ -0,0 +1,63 @@
// 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.dateadd
description: Temporal.Calendar.prototype.dateAdd add duration with weeks and calculate correctly.
info: |
8. Let result be ? AddISODate(date.[[ISOYear]], date.[[ISOMonth]], date.[[ISODay]], duration.[[Years]], duration.[[Months]], duration.[[Weeks]], duration.[[Days]], overflow).
features: [Temporal]
includes: [temporalHelpers.js]
---*/
let cal = new Temporal.Calendar("iso8601");
let p1w = new Temporal.Duration(0,0,1);
let p6w = new Temporal.Duration(0,0,6);
TemporalHelpers.assertPlainDate(
cal.dateAdd("2021-02-19", p1w), 2021, 2, "M02", 26,
"add one week in Feb");
TemporalHelpers.assertPlainDate(
cal.dateAdd("2021-02-27", p1w), 2021, 3, "M03", 6,
"add one week in Feb and result in March");
TemporalHelpers.assertPlainDate(
cal.dateAdd("2020-02-27", p1w), 2020, 3, "M03", 5,
"add one week in Feb and result in March in a leap year");
TemporalHelpers.assertPlainDate(
cal.dateAdd("2021-12-24", p1w), 2021, 12, "M12", 31,
"add one week and result in the last day of a year");
TemporalHelpers.assertPlainDate(
cal.dateAdd("2021-12-25", p1w), 2022, 1, "M01", 1,
"add one week and result in the first day of next year");
TemporalHelpers.assertPlainDate(
cal.dateAdd("2021-01-27", p1w), 2021, 2, "M02", 3,
"add one week and result in next month from a month with 31 days");
TemporalHelpers.assertPlainDate(
cal.dateAdd("2021-06-27", p1w), 2021, 7, "M07", 4,
"add one week and result in next month from a month with 30 days");
TemporalHelpers.assertPlainDate(
cal.dateAdd("2021-07-27", p1w), 2021, 8, "M08", 3,
"add one week and result in next month from a month with 31 days");
TemporalHelpers.assertPlainDate(
cal.dateAdd("2021-02-19", p6w), 2021, 4, "M04", 2,
"add six weeks and result in next month from Feb in a non leap year");
TemporalHelpers.assertPlainDate(
cal.dateAdd("2020-02-19", p6w), 2020, 4, "M04", 1,
"add six weeks and result in next month from Feb in a leap year");
TemporalHelpers.assertPlainDate(
cal.dateAdd("2021-12-24", p6w), 2022, 2, "M02", 4,
"add six weeks and result in the next year");
TemporalHelpers.assertPlainDate(
cal.dateAdd("2021-01-27", p6w), 2021, 3, "M03", 10,
"add six weeks and result in the same year");
TemporalHelpers.assertPlainDate(
cal.dateAdd("2020-01-27", p6w), 2020, 3, "M03", 9,
"add six weeks and result in the same year");
TemporalHelpers.assertPlainDate(
cal.dateAdd("2021-06-27", p6w), 2021, 8, "M08", 8,
"add six weeks and result in the same year crossing month of 30 and 31 days");
TemporalHelpers.assertPlainDate(
cal.dateAdd("2021-07-27", p6w), 2021, 9, "M09", 7,
"add six weeks and result in the same year crossing month of 31 and 31 days");

View File

@ -0,0 +1,45 @@
// 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.dateadd
description: Temporal.Calendar.prototype.dateAdd add duration with years, months and days and calculate correctly.
info: |
8. Let result be ? AddISODate(date.[[ISOYear]], date.[[ISOMonth]], date.[[ISODay]], duration.[[Years]], duration.[[Months]], duration.[[Weeks]], duration.[[Days]], overflow).
features: [Temporal]
includes: [temporalHelpers.js]
---*/
let cal = new Temporal.Calendar("iso8601");
let p1y2m4d = new Temporal.Duration(1,2,0,4);
TemporalHelpers.assertPlainDate(
cal.dateAdd("2021-07-16", p1y2m4d), 2022, 9, "M09", 20,
"add one year two months and 4 days");
TemporalHelpers.assertPlainDate(
cal.dateAdd("2021-02-27", p1y2m4d), 2022, 5, "M05", 1,
"add one year two months and 4 days and roll into new month from a month of 30 days");
TemporalHelpers.assertPlainDate(
cal.dateAdd("2021-01-28", p1y2m4d), 2022, 4, "M04", 1,
"add one year two months and 4 days and roll into new month from a month of 31 days");
TemporalHelpers.assertPlainDate(
cal.dateAdd("2021-02-26", p1y2m4d), 2022, 4, "M04", 30,
"add one year two months and 4 days which roll from March to April in a non leap year");
TemporalHelpers.assertPlainDate(
cal.dateAdd("2023-02-26", p1y2m4d), 2024, 4, "M04", 30,
"add one year two months and 4 days which roll from March to April in a leap year");
TemporalHelpers.assertPlainDate(
cal.dateAdd("2021-12-30", p1y2m4d), 2023, 3, "M03", 4,
"add one year two months and 4 days which roll month into new year and roll day into March in non leap year");
TemporalHelpers.assertPlainDate(
cal.dateAdd("2022-12-30", p1y2m4d), 2024, 3, "M03", 4,
"add one year two months and 4 days which roll month into new year and roll day into March in leap year");
TemporalHelpers.assertPlainDate(
cal.dateAdd("2022-12-29", p1y2m4d), 2024, 3, "M03", 4,
"add one year two months and 4 days which roll month into new year and roll day into March in leap year");
TemporalHelpers.assertPlainDate(
cal.dateAdd("2021-07-30", p1y2m4d), 2022, 10, "M10", 4,
"add one year two months and 4 days which roll into a new month from a month with 30 days");
TemporalHelpers.assertPlainDate(
cal.dateAdd("2021-06-30", p1y2m4d), 2022, 9, "M09", 3,
"add one year two months and 4 days which roll into a new month from a month with 31 days");

View File

@ -0,0 +1,27 @@
// 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.dateadd
description: Temporal.Calendar.prototype.dateAdd add duration with years and months and calculate correctly.
info: |
8. Let result be ? AddISODate(date.[[ISOYear]], date.[[ISOMonth]], date.[[ISODay]], duration.[[Years]], duration.[[Months]], duration.[[Weeks]], duration.[[Days]], overflow).
features: [Temporal]
includes: [temporalHelpers.js]
---*/
let cal = new Temporal.Calendar("iso8601");
let p1y2m = new Temporal.Duration(1,2);
TemporalHelpers.assertPlainDate(
cal.dateAdd("2021-07-16", p1y2m), 2022, 9, "M09", 16,
"add one year and 2 months");
TemporalHelpers.assertPlainDate(
cal.dateAdd("2021-11-30", p1y2m), 2023, 1, "M01", 30,
"add one year and 2 months roll into a new year");
TemporalHelpers.assertPlainDate(
cal.dateAdd("2021-12-31", p1y2m), 2023, 2, "M02", 28,
"add one year and 2 months roll into a new year and constrain in Feb 28 of a non leap year");
TemporalHelpers.assertPlainDate(
cal.dateAdd("2022-12-31", p1y2m), 2024, 2, "M02", 29,
"add one year and 2 months roll into a new year and constrain in Feb 29 of a leap year");

View File

@ -0,0 +1,30 @@
// 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.dateadd
description: Temporal.Calendar.prototype.dateAdd add duration with years and weeks and calculate correctly.
info: |
8. Let result be ? AddISODate(date.[[ISOYear]], date.[[ISOMonth]], date.[[ISODay]], duration.[[Years]], duration.[[Months]], duration.[[Weeks]], duration.[[Days]], overflow).
features: [Temporal]
includes: [temporalHelpers.js]
---*/
let cal = new Temporal.Calendar("iso8601");
let p1y2w = new Temporal.Duration(1,0,2);
TemporalHelpers.assertPlainDate(
cal.dateAdd("2020-02-28", p1y2w), 2021, 3, "M03", 14,
"add 1 year and 2 weeks to Feb 28 and cause roll into March in a non leap year");
TemporalHelpers.assertPlainDate(
cal.dateAdd("2020-02-29", p1y2w), 2021, 3, "M03", 14,
"add 1 year and 2 weeks to Feb 29 and cause roll into March in a non leap year");
TemporalHelpers.assertPlainDate(
cal.dateAdd("2019-02-28", p1y2w), 2020, 3, "M03", 13,
"add 1 year and 2 weeks to Feb 28 and cause roll into March in a leap year");
TemporalHelpers.assertPlainDate(
cal.dateAdd("2021-02-28", p1y2w), 2022, 3, "M03", 14,
"add 1 year and 2 weeks to Feb 28 and cause roll into March in a non leap year");
TemporalHelpers.assertPlainDate(
cal.dateAdd("2020-12-28", p1y2w), 2022, 1, "M01", 11,
"add 1 year and 2 weeks and cause roll into a new year");

View File

@ -0,0 +1,25 @@
// 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.dateadd
description: Temporal.Calendar.prototype.dateAdd add duration with years only calculate correctly.
info: |
8. Let result be ? AddISODate(date.[[ISOYear]], date.[[ISOMonth]], date.[[ISODay]], duration.[[Years]], duration.[[Months]], duration.[[Weeks]], duration.[[Days]], overflow).
features: [Temporal]
includes: [temporalHelpers.js]
---*/
let cal = new Temporal.Calendar("iso8601");
let p1y = new Temporal.Duration(1);
let p4y = new Temporal.Duration(4);
TemporalHelpers.assertPlainDate(
cal.dateAdd("2020-02-29", p1y), 2021, 2, "M02", 28,
"add one year on Feb 29");
TemporalHelpers.assertPlainDate(
cal.dateAdd("2020-02-29", p4y), 2024, 2, "M02", 29,
"add four years on Feb 29");
TemporalHelpers.assertPlainDate(
cal.dateAdd("2021-07-16", p1y), 2022, 7, "M07", 16,
"add one year on other date");

View File

@ -1,50 +0,0 @@
// 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.datefromfields
description: Temporal.Calendar.prototype.dateFromFields
info: |
1. Let calendar be the this value.
2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]).
3. Assert: calendar.[[Identifier]] is "iso8601".
4. If Type(fields) is not Object, throw a TypeError exception.
5. Set options to ? GetOptionsObject(options).
6. Let result be ? ISODateFromFields(fields, options).
7. Return ? CreateTemporalDate(result.[[Year]], result.[[Month]], result.[[Day]], calendar).
features: [Temporal]
---*/
let cal = new Temporal.Calendar("iso8601")
assert.sameValue("2021-07-15", cal.dateFromFields({year: 2021, month: 7, day: 15}).toJSON());
assert.sameValue("2021-07-03", cal.dateFromFields({year: 2021, month: 7, day: 3}).toJSON());
assert.sameValue("2021-12-31", cal.dateFromFields({year: 2021, month: 12, day: 31}).toJSON());
assert.sameValue("2021-07-15", cal.dateFromFields({year: 2021, monthCode: "M07", day: 15}).toJSON());
assert.sameValue("2021-07-03", cal.dateFromFields({year: 2021, monthCode: "M07", day: 3}).toJSON());
assert.sameValue("2021-12-31", cal.dateFromFields({year: 2021, monthCode: "M12", day: 31}).toJSON());
assert.sameValue("2021-01-31", cal.dateFromFields({year: 2021, month: 1, day: 133}).toJSON());
assert.sameValue("2021-02-28", cal.dateFromFields({year: 2021, month: 2, day: 133}).toJSON());
assert.sameValue("2021-03-31", cal.dateFromFields({year: 2021, month: 3, day: 9033}).toJSON());
assert.sameValue("2021-04-30", cal.dateFromFields({year: 2021, month: 4, day: 50}).toJSON());
assert.sameValue("2021-05-31", cal.dateFromFields({year: 2021, month: 5, day: 77}).toJSON());
assert.sameValue("2021-06-30", cal.dateFromFields({year: 2021, month: 6, day: 33}).toJSON());
assert.sameValue("2021-07-31", cal.dateFromFields({year: 2021, month: 7, day: 33}).toJSON());
assert.sameValue("2021-08-31", cal.dateFromFields({year: 2021, month: 8, day: 300}).toJSON());
assert.sameValue("2021-09-30", cal.dateFromFields({year: 2021, month: 9, day: 400}).toJSON());
assert.sameValue("2021-10-31", cal.dateFromFields({year: 2021, month: 10, day: 400}).toJSON());
assert.sameValue("2021-11-30", cal.dateFromFields({year: 2021, month: 11, day: 400}).toJSON());
assert.sameValue("2021-12-31", cal.dateFromFields({year: 2021, month: 12, day: 500}).toJSON());
assert.sameValue("2021-12-31", cal.dateFromFields({year: 2021, month: 13, day: 500}).toJSON());
assert.sameValue("2021-12-31", cal.dateFromFields({year: 2021, month: 999999, day: 500}).toJSON());
assert.sameValue("2021-01-31", cal.dateFromFields({year: 2021, monthCode: "M01", day: 133}).toJSON());
assert.sameValue("2021-02-28", cal.dateFromFields({year: 2021, monthCode: "M02", day: 133}).toJSON());
assert.sameValue("2021-03-31", cal.dateFromFields({year: 2021, monthCode: "M03", day: 9033}).toJSON());
assert.sameValue("2021-04-30", cal.dateFromFields({year: 2021, monthCode: "M04", day: 50}).toJSON());
assert.sameValue("2021-05-31", cal.dateFromFields({year: 2021, monthCode: "M05", day: 77}).toJSON());
assert.sameValue("2021-06-30", cal.dateFromFields({year: 2021, monthCode: "M06", day: 33}).toJSON());
assert.sameValue("2021-07-31", cal.dateFromFields({year: 2021, monthCode: "M07", day: 33}).toJSON());
assert.sameValue("2021-08-31", cal.dateFromFields({year: 2021, monthCode: "M08", day: 300}).toJSON());
assert.sameValue("2021-09-30", cal.dateFromFields({year: 2021, monthCode: "M09", day: 400}).toJSON());
assert.sameValue("2021-10-31", cal.dateFromFields({year: 2021, monthCode: "M10", day: 400}).toJSON());
assert.sameValue("2021-11-30", cal.dateFromFields({year: 2021, monthCode: "M11", day: 400}).toJSON());
assert.sameValue("2021-12-31", cal.dateFromFields({year: 2021, monthCode: "M12", day: 500}).toJSON());

View File

@ -1,18 +0,0 @@
// 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.datefromfields
description: Temporal.Calendar.prototype.dateFromFields should throw TypeError from GetOptionsObject.
info: |
4. If Type(fields) is not Object, throw a TypeError exception.
features: [Temporal]
---*/
let cal = new Temporal.Calendar("iso8601")
let fields = {year: 2021, month: 7, day: 20};
let notObjectList = [
null, "string", Symbol('efg'), true, false, Infinity, NaN, 123, 456n];
notObjectList.forEach(function(options) {
assert.throws(TypeError, () => cal.dateFromFields(fields, options),
"options is not object");
})

View File

@ -1,15 +0,0 @@
// 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.datefromfields
description: Temporal.Calendar.prototype.dateFromFields should throw TypeError while calendar has no [[InitializedTemporalCalendar]]
info: |
1. Let calendar be the this value.
2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]).
features: [Temporal]
---*/
let cal = new Temporal.Calendar("iso8601")
let badCal = {dateFromFields: cal.dateFromFields};
assert.throws(TypeError, () => badCal.dateFromFields({year: 2021, month: 3, day: 17}),
"calendar has no [[InitializedTemporalCalendar]]");