mirror of
https://github.com/tc39/test262.git
synced 2025-11-28 17:43:19 +01:00
Intl Era Monthcode: New durations used for both addition and subtraction
Make sure we test each of the new durations that were moved from staging tests in both positive and negative form.
This commit is contained in:
parent
714b34cd99
commit
dbb09a19f1
@ -18,6 +18,7 @@ const years1n = new Temporal.Duration(-1);
|
||||
const years5 = new Temporal.Duration(5);
|
||||
const years5n = new Temporal.Duration(-5);
|
||||
const years3months6days17 = new Temporal.Duration(3, 6, 0, 17);
|
||||
const years3months6days17n = new Temporal.Duration(-3, -6, 0, -17);
|
||||
|
||||
const date201802 = Temporal.PlainDate.from({ year: 2018, monthCode: "M02", day: 1, calendar }, options);
|
||||
const date202302 = Temporal.PlainDate.from({ year: 2023, monthCode: "M02", day: 29, calendar }, options);
|
||||
@ -68,6 +69,11 @@ TemporalHelpers.assertPlainDate(
|
||||
2001, 6, "M05", 18, "Adding 3 years/6 months/17 days to day 1 of a month"
|
||||
);
|
||||
|
||||
TemporalHelpers.assertPlainDate(
|
||||
date199712.add(years3months6days17n),
|
||||
1994, 5, "M05", 14, "Subtracting 3 years/6 months/17 days from day 1 of a month"
|
||||
);
|
||||
|
||||
// Months
|
||||
|
||||
const months1 = new Temporal.Duration(0, 1);
|
||||
@ -75,12 +81,14 @@ const months1n = new Temporal.Duration(0, -1);
|
||||
const months4 = new Temporal.Duration(0, 4);
|
||||
const months4n = new Temporal.Duration(0, -4);
|
||||
const months6 = new Temporal.Duration(0, 6);
|
||||
const months6n = new Temporal.Duration(0, -6);
|
||||
const durations = [
|
||||
months1,
|
||||
months1n,
|
||||
months4,
|
||||
months4n,
|
||||
months6
|
||||
months6,
|
||||
months6n,
|
||||
];
|
||||
|
||||
const date201901 = Temporal.PlainDate.from({ year: 2019, monthCode: "M01", day: 1, calendar }, options);
|
||||
@ -141,6 +149,11 @@ TemporalHelpers.assertPlainDate(
|
||||
2001, 6, "M05", 1, "Adding 6 months, with result in next year (leap year)"
|
||||
);
|
||||
|
||||
TemporalHelpers.assertPlainDate(
|
||||
date200012.add(months6n),
|
||||
2000, 6, "M06", 1, "Subtracting 6 months, with result in same year"
|
||||
);
|
||||
|
||||
for (var duration of durations) {
|
||||
for (var start of dates) {
|
||||
const end = start.add(duration);
|
||||
@ -183,6 +196,7 @@ for (var duration of durations) {
|
||||
const months2weeks3 = new Temporal.Duration(0, /* months = */ 2, /* weeks = */ 3);
|
||||
const months2weeks3n = new Temporal.Duration(0, -2, -3);
|
||||
const weeks40 = new Temporal.Duration(0, 0, /* weeks = */ 40);
|
||||
const weeks40n = new Temporal.Duration(0, 0, -40);
|
||||
|
||||
const date202101 = Temporal.PlainDate.from({ year: 2021, monthCode: "M01", day: 1, calendar }, options);
|
||||
const date20000101 = Temporal.PlainDate.from({ year: 2000, month: 1, day: 1, calendar }, options);
|
||||
@ -212,11 +226,17 @@ TemporalHelpers.assertPlainDate(
|
||||
2000, 10, "M10", 16, "add 40 weeks, ending in same year"
|
||||
);
|
||||
|
||||
TemporalHelpers.assertPlainDate(
|
||||
date20000101.add(weeks40n),
|
||||
1999, 3, "M03", 16, "subtract 40 weeks, ending in previous year"
|
||||
);
|
||||
|
||||
// Days
|
||||
|
||||
const days10 = new Temporal.Duration(0, 0, 0, /* days = */ 10);
|
||||
const days10n = new Temporal.Duration(0, 0, 0, -10);
|
||||
const days200 = new Temporal.Duration(0, 0, 0, /* days = */ 200);
|
||||
const days200n = new Temporal.Duration(0, 0, 0, -200);
|
||||
|
||||
const date20210129 = Temporal.PlainDate.from({ year: 2021, monthCode: "M01", day: 29, calendar }, options);
|
||||
|
||||
@ -254,3 +274,8 @@ TemporalHelpers.assertPlainDate(
|
||||
date20000101.add(days200),
|
||||
2000, 7, "M07", 24, "add 200 days, ending in same year"
|
||||
);
|
||||
|
||||
TemporalHelpers.assertPlainDate(
|
||||
date20000101.add(days200n),
|
||||
1999, 6, "M06", 8, "subtract 200 days, ending in previous year"
|
||||
);
|
||||
|
||||
@ -18,6 +18,7 @@ const years1n = new Temporal.Duration(-1);
|
||||
const years5 = new Temporal.Duration(5);
|
||||
const years5n = new Temporal.Duration(-5);
|
||||
const years3months6days17 = new Temporal.Duration(3, 6, 0, 17);
|
||||
const years3months6days17n = new Temporal.Duration(-3, -6, 0, -17);
|
||||
|
||||
const date201802 = Temporal.PlainDate.from({ year: 2018, monthCode: "M02", day: 1, calendar }, options);
|
||||
const date202302 = Temporal.PlainDate.from({ year: 2023, monthCode: "M02", day: 29, calendar }, options);
|
||||
@ -68,6 +69,11 @@ TemporalHelpers.assertPlainDate(
|
||||
2001, 6, "M05", 18, "Adding 3 years/6 months/17 days to day 1 of a month"
|
||||
);
|
||||
|
||||
TemporalHelpers.assertPlainDate(
|
||||
date199712.add(years3months6days17n),
|
||||
1994, 5, "M05", 14, "Subtracting 3 years/6 months/17 days from day 1 of a month"
|
||||
);
|
||||
|
||||
// Months
|
||||
|
||||
const months1 = new Temporal.Duration(0, 1);
|
||||
@ -75,12 +81,14 @@ const months1n = new Temporal.Duration(0, -1);
|
||||
const months4 = new Temporal.Duration(0, 4);
|
||||
const months4n = new Temporal.Duration(0, -4);
|
||||
const months6 = new Temporal.Duration(0, 6);
|
||||
const months6n = new Temporal.Duration(0, -6);
|
||||
const durations = [
|
||||
months1,
|
||||
months1n,
|
||||
months4,
|
||||
months4n,
|
||||
months6
|
||||
months6,
|
||||
months6n,
|
||||
];
|
||||
|
||||
const date201901 = Temporal.PlainDate.from({ year: 2019, monthCode: "M01", day: 1, calendar }, options);
|
||||
@ -141,6 +149,11 @@ TemporalHelpers.assertPlainDate(
|
||||
2001, 6, "M05", 1, "Adding 6 months, with result in next year (leap year)"
|
||||
);
|
||||
|
||||
TemporalHelpers.assertPlainDate(
|
||||
date200012.add(months6n),
|
||||
2000, 6, "M06", 1, "Subtracting 6 months, with result in same year"
|
||||
);
|
||||
|
||||
for (var duration of durations) {
|
||||
for (var start of dates) {
|
||||
const end = start.add(duration);
|
||||
@ -183,6 +196,7 @@ for (var duration of durations) {
|
||||
const months2weeks3 = new Temporal.Duration(0, /* months = */ 2, /* weeks = */ 3);
|
||||
const months2weeks3n = new Temporal.Duration(0, -2, -3);
|
||||
const weeks40 = new Temporal.Duration(0, 0, /* weeks = */ 40);
|
||||
const weeks40n = new Temporal.Duration(0, 0, -40);
|
||||
|
||||
const date202101 = Temporal.PlainDate.from({ year: 2021, monthCode: "M01", day: 1, calendar }, options);
|
||||
const date20000101 = Temporal.PlainDate.from({ year: 2000, month: 1, day: 1, calendar }, options);
|
||||
@ -212,11 +226,17 @@ TemporalHelpers.assertPlainDate(
|
||||
2000, 10, "M10", 16, "add 40 weeks, ending in same year"
|
||||
);
|
||||
|
||||
TemporalHelpers.assertPlainDate(
|
||||
date20000101.add(weeks40n),
|
||||
1999, 3, "M03", 16, "subtract 40 weeks, ending in previous year"
|
||||
);
|
||||
|
||||
// Days
|
||||
|
||||
const days10 = new Temporal.Duration(0, 0, 0, /* days = */ 10);
|
||||
const days10n = new Temporal.Duration(0, 0, 0, -10);
|
||||
const days200 = new Temporal.Duration(0, 0, 0, /* days = */ 200);
|
||||
const days200n = new Temporal.Duration(0, 0, 0, -200);
|
||||
|
||||
const date20210129 = Temporal.PlainDate.from({ year: 2021, monthCode: "M01", day: 29, calendar }, options);
|
||||
|
||||
@ -254,3 +274,8 @@ TemporalHelpers.assertPlainDate(
|
||||
date20000101.add(days200),
|
||||
2000, 7, "M07", 24, "add 200 days, ending in same year"
|
||||
);
|
||||
|
||||
TemporalHelpers.assertPlainDate(
|
||||
date20000101.add(days200n),
|
||||
1999, 6, "M06", 8, "subtract 200 days, ending in previous year"
|
||||
);
|
||||
|
||||
@ -17,7 +17,8 @@ const years1 = new Temporal.Duration(-1);
|
||||
const years1n = new Temporal.Duration(1);
|
||||
const years5 = new Temporal.Duration(-5);
|
||||
const years5n = new Temporal.Duration(5);
|
||||
const years3months6days17 = new Temporal.Duration(3, 6, 0, 17);
|
||||
const years3months6days17 = new Temporal.Duration(-3, -6, 0, -17);
|
||||
const years3months6days17n = new Temporal.Duration(3, 6, 0, 17);
|
||||
|
||||
const date201802 = Temporal.PlainDate.from({ year: 2018, monthCode: "M02", day: 1, calendar }, options);
|
||||
const date202302 = Temporal.PlainDate.from({ year: 2023, monthCode: "M02", day: 29, calendar }, options);
|
||||
@ -65,6 +66,11 @@ TemporalHelpers.assertPlainDate(
|
||||
|
||||
TemporalHelpers.assertPlainDate(
|
||||
date199712.subtract(years3months6days17),
|
||||
2001, 6, "M05", 18, "Adding 3 years/6 months/17 days to day 1 of a month"
|
||||
);
|
||||
|
||||
TemporalHelpers.assertPlainDate(
|
||||
date199712.subtract(years3months6days17n),
|
||||
1994, 5, "M05", 14, "Subtracting 3 years/6 months/17 days from day 1 of a month"
|
||||
);
|
||||
|
||||
@ -74,13 +80,15 @@ const months1 = new Temporal.Duration(0, -1);
|
||||
const months1n = new Temporal.Duration(0, 1);
|
||||
const months4 = new Temporal.Duration(0, -4);
|
||||
const months4n = new Temporal.Duration(0, 4);
|
||||
const months6 = new Temporal.Duration(0, 6);
|
||||
const months6 = new Temporal.Duration(0, -6);
|
||||
const months6n = new Temporal.Duration(0, 6);
|
||||
const durations = [
|
||||
months1,
|
||||
months1n,
|
||||
months4,
|
||||
months4n,
|
||||
months6
|
||||
months6,
|
||||
months6n,
|
||||
];
|
||||
|
||||
const date201901 = Temporal.PlainDate.from({ year: 2019, monthCode: "M01", day: 1, calendar }, options);
|
||||
@ -138,6 +146,11 @@ TemporalHelpers.assertPlainDate(
|
||||
|
||||
TemporalHelpers.assertPlainDate(
|
||||
date200012.subtract(months6),
|
||||
2001, 6, "M05", 1, "Adding 6 months, with result in next year (leap year)"
|
||||
);
|
||||
|
||||
TemporalHelpers.assertPlainDate(
|
||||
date200012.subtract(months6n),
|
||||
2000, 6, "M06", 1, "Subtracting 6 months, with result in same year"
|
||||
);
|
||||
|
||||
@ -182,7 +195,8 @@ for (var duration of durations) {
|
||||
|
||||
const months2weeks3 = new Temporal.Duration(0, /* months = */ -2, /* weeks = */ -3);
|
||||
const months2weeks3n = new Temporal.Duration(0, 2, 3);
|
||||
const weeks40 = new Temporal.Duration(0, 0, /* weeks = */ 40);
|
||||
const weeks40 = new Temporal.Duration(0, 0, /* weeks = */ -40);
|
||||
const weeks40n = new Temporal.Duration(0, 0, 40);
|
||||
|
||||
const date202101 = Temporal.PlainDate.from({ year: 2021, monthCode: "M01", day: 1, calendar }, options);
|
||||
const date20000101 = Temporal.PlainDate.from({ year: 2000, month: 1, day: 1, calendar }, options);
|
||||
@ -209,6 +223,11 @@ TemporalHelpers.assertPlainDate(
|
||||
|
||||
TemporalHelpers.assertPlainDate(
|
||||
date20000101.subtract(weeks40),
|
||||
2000, 10, "M10", 16, "add 40 weeks, ending in same year"
|
||||
);
|
||||
|
||||
TemporalHelpers.assertPlainDate(
|
||||
date20000101.subtract(weeks40n),
|
||||
1999, 3, "M03", 16, "subtract 40 weeks, ending in previous year"
|
||||
);
|
||||
|
||||
@ -216,7 +235,8 @@ TemporalHelpers.assertPlainDate(
|
||||
|
||||
const days10 = new Temporal.Duration(0, 0, 0, /* days = */ -10);
|
||||
const days10n = new Temporal.Duration(0, 0, 0, 10);
|
||||
const days200 = new Temporal.Duration(0, 0, 0, /* days = */ 200);
|
||||
const days200 = new Temporal.Duration(0, 0, 0, /* days = */ -200);
|
||||
const days200n = new Temporal.Duration(0, 0, 0, 200);
|
||||
|
||||
const date20210129 = Temporal.PlainDate.from({ year: 2021, monthCode: "M01", day: 29, calendar }, options);
|
||||
|
||||
@ -252,5 +272,10 @@ TemporalHelpers.assertPlainDate(
|
||||
|
||||
TemporalHelpers.assertPlainDate(
|
||||
date20000101.subtract(days200),
|
||||
2000, 7, "M07", 24, "add 200 days, ending in same year"
|
||||
);
|
||||
|
||||
TemporalHelpers.assertPlainDate(
|
||||
date20000101.subtract(days200n),
|
||||
1999, 6, "M06", 8, "subtract 200 days, ending in previous year"
|
||||
);
|
||||
|
||||
@ -17,7 +17,8 @@ const years1 = new Temporal.Duration(-1);
|
||||
const years1n = new Temporal.Duration(1);
|
||||
const years5 = new Temporal.Duration(-5);
|
||||
const years5n = new Temporal.Duration(5);
|
||||
const years3months6days17 = new Temporal.Duration(3, 6, 0, 17);
|
||||
const years3months6days17 = new Temporal.Duration(-3, -6, 0, -17);
|
||||
const years3months6days17n = new Temporal.Duration(3, 6, 0, 17);
|
||||
|
||||
const date201802 = Temporal.PlainDate.from({ year: 2018, monthCode: "M02", day: 1, calendar }, options);
|
||||
const date202302 = Temporal.PlainDate.from({ year: 2023, monthCode: "M02", day: 29, calendar }, options);
|
||||
@ -65,6 +66,11 @@ TemporalHelpers.assertPlainDate(
|
||||
|
||||
TemporalHelpers.assertPlainDate(
|
||||
date199712.subtract(years3months6days17),
|
||||
2001, 6, "M05", 18, "Adding 3 years/6 months/17 days to day 1 of a month"
|
||||
);
|
||||
|
||||
TemporalHelpers.assertPlainDate(
|
||||
date199712.subtract(years3months6days17n),
|
||||
1994, 5, "M05", 14, "Subtracting 3 years/6 months/17 days from day 1 of a month"
|
||||
);
|
||||
|
||||
@ -74,13 +80,15 @@ const months1 = new Temporal.Duration(0, -1);
|
||||
const months1n = new Temporal.Duration(0, 1);
|
||||
const months4 = new Temporal.Duration(0, -4);
|
||||
const months4n = new Temporal.Duration(0, 4);
|
||||
const months6 = new Temporal.Duration(0, 6);
|
||||
const months6 = new Temporal.Duration(0, -6);
|
||||
const months6n = new Temporal.Duration(0, 6);
|
||||
const durations = [
|
||||
months1,
|
||||
months1n,
|
||||
months4,
|
||||
months4n,
|
||||
months6
|
||||
months6,
|
||||
months6n,
|
||||
];
|
||||
|
||||
const date201901 = Temporal.PlainDate.from({ year: 2019, monthCode: "M01", day: 1, calendar }, options);
|
||||
@ -138,17 +146,22 @@ TemporalHelpers.assertPlainDate(
|
||||
|
||||
TemporalHelpers.assertPlainDate(
|
||||
date200012.subtract(months6),
|
||||
2001, 6, "M05", 1, "Adding 6 months, with result in next year (leap year)"
|
||||
);
|
||||
|
||||
TemporalHelpers.assertPlainDate(
|
||||
date200012.subtract(months6n),
|
||||
2000, 6, "M06", 1, "Subtracting 6 months, with result in same year"
|
||||
);
|
||||
|
||||
for (var duration of durations) {
|
||||
for (var start of dates) {
|
||||
const end = start.subtract(duration.negated());
|
||||
const end = start.subtract(duration);
|
||||
|
||||
// startYesterday = start - (1 day)
|
||||
const startYesterday = start.subtract({ days: 1 });
|
||||
// endYesterday = startYesterday + duration
|
||||
const endYesterday = startYesterday.subtract(duration.negated());
|
||||
const endYesterday = startYesterday.subtract(duration);
|
||||
// When adding months, the result day should be the same
|
||||
// unless there are fewer days in the destination month than the source day
|
||||
assert.sameValue(endYesterday.day, Math.min(startYesterday.day, endYesterday.daysInMonth), "adding months should result in same day");
|
||||
@ -182,7 +195,8 @@ for (var duration of durations) {
|
||||
|
||||
const months2weeks3 = new Temporal.Duration(0, /* months = */ -2, /* weeks = */ -3);
|
||||
const months2weeks3n = new Temporal.Duration(0, 2, 3);
|
||||
const weeks40 = new Temporal.Duration(0, 0, /* weeks = */ 40);
|
||||
const weeks40 = new Temporal.Duration(0, 0, /* weeks = */ -40);
|
||||
const weeks40n = new Temporal.Duration(0, 0, 40);
|
||||
|
||||
const date202101 = Temporal.PlainDate.from({ year: 2021, monthCode: "M01", day: 1, calendar }, options);
|
||||
const date20000101 = Temporal.PlainDate.from({ year: 2000, month: 1, day: 1, calendar }, options);
|
||||
@ -209,6 +223,11 @@ TemporalHelpers.assertPlainDate(
|
||||
|
||||
TemporalHelpers.assertPlainDate(
|
||||
date20000101.subtract(weeks40),
|
||||
2000, 10, "M10", 16, "add 40 weeks, ending in same year"
|
||||
);
|
||||
|
||||
TemporalHelpers.assertPlainDate(
|
||||
date20000101.subtract(weeks40n),
|
||||
1999, 3, "M03", 16, "subtract 40 weeks, ending in previous year"
|
||||
);
|
||||
|
||||
@ -216,7 +235,8 @@ TemporalHelpers.assertPlainDate(
|
||||
|
||||
const days10 = new Temporal.Duration(0, 0, 0, /* days = */ -10);
|
||||
const days10n = new Temporal.Duration(0, 0, 0, 10);
|
||||
const days200 = new Temporal.Duration(0, 0, 0, /* days = */ 200);
|
||||
const days200 = new Temporal.Duration(0, 0, 0, /* days = */ -200);
|
||||
const days200n = new Temporal.Duration(0, 0, 0, 200);
|
||||
|
||||
const date20210129 = Temporal.PlainDate.from({ year: 2021, monthCode: "M01", day: 29, calendar }, options);
|
||||
|
||||
@ -252,5 +272,10 @@ TemporalHelpers.assertPlainDate(
|
||||
|
||||
TemporalHelpers.assertPlainDate(
|
||||
date20000101.subtract(days200),
|
||||
2000, 7, "M07", 24, "add 200 days, ending in same year"
|
||||
);
|
||||
|
||||
TemporalHelpers.assertPlainDate(
|
||||
date20000101.subtract(days200n),
|
||||
1999, 6, "M06", 8, "subtract 200 days, ending in previous year"
|
||||
);
|
||||
|
||||
@ -18,6 +18,7 @@ const years1n = new Temporal.Duration(-1);
|
||||
const years5 = new Temporal.Duration(5);
|
||||
const years5n = new Temporal.Duration(-5);
|
||||
const years3months6days17 = new Temporal.Duration(3, 6, 0, 17);
|
||||
const years3months6days17n = new Temporal.Duration(-3, -6, 0, -17);
|
||||
|
||||
const date201802 = Temporal.PlainDateTime.from({ year: 2018, monthCode: "M02", day: 1, hour: 12, minute: 34, calendar }, options);
|
||||
const date202302 = Temporal.PlainDateTime.from({ year: 2023, monthCode: "M02", day: 29, hour: 12, minute: 34, calendar }, options);
|
||||
@ -68,6 +69,11 @@ TemporalHelpers.assertPlainDateTime(
|
||||
2001, 6, "M05", 18, 12, 34, 0, 0, 0, 0, "Adding 3 years/6 months/17 days to day 1 of a month"
|
||||
);
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
date199712.add(years3months6days17n),
|
||||
1994, 5, "M05", 14, 12, 34, 0, 0, 0, 0, "Subtracting 3 years/6 months/17 days from day 1 of a month"
|
||||
);
|
||||
|
||||
// Months
|
||||
|
||||
const months1 = new Temporal.Duration(0, 1);
|
||||
@ -75,6 +81,7 @@ const months1n = new Temporal.Duration(0, -1);
|
||||
const months4 = new Temporal.Duration(0, 4);
|
||||
const months4n = new Temporal.Duration(0, -4);
|
||||
const months6 = new Temporal.Duration(0, 6);
|
||||
const months6n = new Temporal.Duration(0, -6);
|
||||
|
||||
const date201901 = Temporal.PlainDateTime.from({ year: 2019, monthCode: "M01", day: 1, hour: 12, minute: 34, calendar }, options);
|
||||
const date201906 = Temporal.PlainDateTime.from({ year: 2019, monthCode: "M06", day: 1, hour: 12, minute: 34, calendar }, options);
|
||||
@ -127,11 +134,17 @@ TemporalHelpers.assertPlainDateTime(
|
||||
2001, 6, "M05", 1, 12, 34, 0, 0, 0, 0, "Adding 6 months, with result in next year (leap year)"
|
||||
);
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
date200012.add(months6n),
|
||||
2000, 6, "M06", 1, 12, 34, 0, 0, 0, 0, "Subtracting 6 months, with result in same year"
|
||||
);
|
||||
|
||||
// Weeks
|
||||
|
||||
const months2weeks3 = new Temporal.Duration(0, /* months = */ 2, /* weeks = */ 3);
|
||||
const months2weeks3n = new Temporal.Duration(0, -2, -3);
|
||||
const weeks40 = new Temporal.Duration(0, 0, /* weeks = */ 40);
|
||||
const weeks40n = new Temporal.Duration(0, 0, -40);
|
||||
|
||||
const date202101 = Temporal.PlainDateTime.from({ year: 2021, monthCode: "M01", day: 1, hour: 12, minute: 34, calendar }, options);
|
||||
const date20000101 = Temporal.PlainDateTime.from({ year: 2000, month: 1, day: 1, hour: 12, minute: 34, calendar }, options);
|
||||
@ -161,11 +174,17 @@ TemporalHelpers.assertPlainDateTime(
|
||||
2000, 10, "M10", 16, 12, 34, 0, 0, 0, 0, "add 40 weeks, ending in same year"
|
||||
);
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
date20000101.add(weeks40n),
|
||||
1999, 3, "M03", 16, 12, 34, 0, 0, 0, 0, "subtract 40 weeks, ending in previous year"
|
||||
);
|
||||
|
||||
// Days
|
||||
|
||||
const days10 = new Temporal.Duration(0, 0, 0, /* days = */ 10);
|
||||
const days10n = new Temporal.Duration(0, 0, 0, -10);
|
||||
const days200 = new Temporal.Duration(0, 0, 0, /* days = */ 200);
|
||||
const days200n = new Temporal.Duration(0, 0, 0, -200);
|
||||
|
||||
const date20210129 = Temporal.PlainDateTime.from({ year: 2021, monthCode: "M01", day: 29, hour: 12, minute: 34, calendar }, options);
|
||||
|
||||
@ -203,3 +222,8 @@ TemporalHelpers.assertPlainDateTime(
|
||||
date20000101.add(days200),
|
||||
2000, 7, "M07", 24, 12, 34, 0, 0, 0, 0, "add 200 days, ending in same year"
|
||||
);
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
date20000101.add(days200n),
|
||||
1999, 6, "M06", 8, 12, 34, 0, 0, 0, 0, "subtract 200 days, ending in previous year"
|
||||
);
|
||||
|
||||
@ -18,6 +18,7 @@ const years1n = new Temporal.Duration(-1);
|
||||
const years5 = new Temporal.Duration(5);
|
||||
const years5n = new Temporal.Duration(-5);
|
||||
const years3months6days17 = new Temporal.Duration(3, 6, 0, 17);
|
||||
const years3months6days17n = new Temporal.Duration(-3, -6, 0, -17);
|
||||
|
||||
const date201802 = Temporal.PlainDateTime.from({ year: 2018, monthCode: "M02", day: 1, hour: 12, minute: 34, calendar }, options);
|
||||
const date202302 = Temporal.PlainDateTime.from({ year: 2023, monthCode: "M02", day: 29, hour: 12, minute: 34, calendar }, options);
|
||||
@ -68,6 +69,11 @@ TemporalHelpers.assertPlainDateTime(
|
||||
2001, 6, "M05", 18, 12, 34, 0, 0, 0, 0, "Adding 3 years/6 months/17 days to day 1 of a month"
|
||||
);
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
date199712.add(years3months6days17n),
|
||||
1994, 5, "M05", 14, 12, 34, 0, 0, 0, 0, "Subtracting 3 years/6 months/17 days from day 1 of a month"
|
||||
);
|
||||
|
||||
// Months
|
||||
|
||||
const months1 = new Temporal.Duration(0, 1);
|
||||
@ -75,6 +81,7 @@ const months1n = new Temporal.Duration(0, -1);
|
||||
const months4 = new Temporal.Duration(0, 4);
|
||||
const months4n = new Temporal.Duration(0, -4);
|
||||
const months6 = new Temporal.Duration(0, 6);
|
||||
const months6n = new Temporal.Duration(0, -6);
|
||||
|
||||
const date201901 = Temporal.PlainDateTime.from({ year: 2019, monthCode: "M01", day: 1, hour: 12, minute: 34, calendar }, options);
|
||||
const date201906 = Temporal.PlainDateTime.from({ year: 2019, monthCode: "M06", day: 1, hour: 12, minute: 34, calendar }, options);
|
||||
@ -127,11 +134,17 @@ TemporalHelpers.assertPlainDateTime(
|
||||
2001, 6, "M05", 1, 12, 34, 0, 0, 0, 0, "Adding 6 months, with result in next year (leap year)"
|
||||
);
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
date200012.add(months6n),
|
||||
2000, 6, "M06", 1, 12, 34, 0, 0, 0, 0, "Subtracting 6 months, with result in same year"
|
||||
);
|
||||
|
||||
// Weeks
|
||||
|
||||
const months2weeks3 = new Temporal.Duration(0, /* months = */ 2, /* weeks = */ 3);
|
||||
const months2weeks3n = new Temporal.Duration(0, -2, -3);
|
||||
const weeks40 = new Temporal.Duration(0, 0, /* weeks = */ 40);
|
||||
const weeks40n = new Temporal.Duration(0, 0, -40);
|
||||
|
||||
const date202101 = Temporal.PlainDateTime.from({ year: 2021, monthCode: "M01", day: 1, hour: 12, minute: 34, calendar }, options);
|
||||
const date20000101 = Temporal.PlainDateTime.from({ year: 2000, month: 1, day: 1, hour: 12, minute: 34, calendar }, options);
|
||||
@ -161,11 +174,17 @@ TemporalHelpers.assertPlainDateTime(
|
||||
2000, 10, "M10", 16, 12, 34, 0, 0, 0, 0, "add 40 weeks, ending in same year"
|
||||
);
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
date20000101.add(weeks40n),
|
||||
1999, 3, "M03", 16, 12, 34, 0, 0, 0, 0, "subtract 40 weeks, ending in previous year"
|
||||
);
|
||||
|
||||
// Days
|
||||
|
||||
const days10 = new Temporal.Duration(0, 0, 0, /* days = */ 10);
|
||||
const days10n = new Temporal.Duration(0, 0, 0, -10);
|
||||
const days200 = new Temporal.Duration(0, 0, 0, /* days = */ 200);
|
||||
const days200n = new Temporal.Duration(0, 0, 0, -200);
|
||||
|
||||
const date20210129 = Temporal.PlainDateTime.from({ year: 2021, monthCode: "M01", day: 29, hour: 12, minute: 34, calendar }, options);
|
||||
|
||||
@ -203,3 +222,8 @@ TemporalHelpers.assertPlainDateTime(
|
||||
date20000101.add(days200),
|
||||
2000, 7, "M07", 24, 12, 34, 0, 0, 0, 0, "add 200 days, ending in same year"
|
||||
);
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
date20000101.add(days200n),
|
||||
1999, 6, "M06", 8, 12, 34, 0, 0, 0, 0, "subtract 200 days, ending in previous year"
|
||||
);
|
||||
|
||||
@ -17,7 +17,8 @@ const years1 = new Temporal.Duration(-1);
|
||||
const years1n = new Temporal.Duration(1);
|
||||
const years5 = new Temporal.Duration(-5);
|
||||
const years5n = new Temporal.Duration(5);
|
||||
const years3months6days17 = new Temporal.Duration(3, 6, 0, 17);
|
||||
const years3months6days17 = new Temporal.Duration(-3, -6, 0, -17);
|
||||
const years3months6days17n = new Temporal.Duration(3, 6, 0, 17);
|
||||
|
||||
const date201802 = Temporal.PlainDateTime.from({ year: 2018, monthCode: "M02", day: 1, hour: 12, minute: 34, calendar }, options);
|
||||
const date202302 = Temporal.PlainDateTime.from({ year: 2023, monthCode: "M02", day: 29, hour: 12, minute: 34, calendar }, options);
|
||||
@ -65,6 +66,11 @@ TemporalHelpers.assertPlainDateTime(
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
date199712.subtract(years3months6days17),
|
||||
2001, 6, "M05", 18, 12, 34, 0, 0, 0, 0, "Adding 3 years/6 months/17 days to day 1 of a month"
|
||||
);
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
date199712.subtract(years3months6days17n),
|
||||
1994, 5, "M05", 14, 12, 34, 0, 0, 0, 0, "Subtracting 3 years/6 months/17 days from day 1 of a month"
|
||||
);
|
||||
|
||||
@ -74,7 +80,8 @@ const months1 = new Temporal.Duration(0, -1);
|
||||
const months1n = new Temporal.Duration(0, 1);
|
||||
const months4 = new Temporal.Duration(0, -4);
|
||||
const months4n = new Temporal.Duration(0, 4);
|
||||
const months6 = new Temporal.Duration(0, 6);
|
||||
const months6 = new Temporal.Duration(0, -6);
|
||||
const months6n = new Temporal.Duration(0, 6);
|
||||
|
||||
const date201901 = Temporal.PlainDateTime.from({ year: 2019, monthCode: "M01", day: 1, hour: 12, minute: 34, calendar }, options);
|
||||
const date201906 = Temporal.PlainDateTime.from({ year: 2019, monthCode: "M06", day: 1, hour: 12, minute: 34, calendar }, options);
|
||||
@ -124,6 +131,11 @@ TemporalHelpers.assertPlainDateTime(
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
date200012.subtract(months6),
|
||||
2001, 6, "M05", 1, 12, 34, 0, 0, 0, 0, "Adding 6 months, with result in next year (leap year)"
|
||||
);
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
date200012.subtract(months6n),
|
||||
2000, 6, "M06", 1, 12, 34, 0, 0, 0, 0, "Subtracting 6 months, with result in same year"
|
||||
);
|
||||
|
||||
@ -131,7 +143,8 @@ TemporalHelpers.assertPlainDateTime(
|
||||
|
||||
const months2weeks3 = new Temporal.Duration(0, /* months = */ -2, /* weeks = */ -3);
|
||||
const months2weeks3n = new Temporal.Duration(0, 2, 3);
|
||||
const weeks40 = new Temporal.Duration(0, 0, /* weeks = */ 40);
|
||||
const weeks40 = new Temporal.Duration(0, 0, /* weeks = */ -40);
|
||||
const weeks40n = new Temporal.Duration(0, 0, 40);
|
||||
|
||||
const date202101 = Temporal.PlainDateTime.from({ year: 2021, monthCode: "M01", day: 1, hour: 12, minute: 34, calendar }, options);
|
||||
const date20000101 = Temporal.PlainDateTime.from({ year: 2000, month: 1, day: 1, hour: 12, minute: 34, calendar }, options);
|
||||
@ -158,6 +171,11 @@ TemporalHelpers.assertPlainDateTime(
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
date20000101.subtract(weeks40),
|
||||
2000, 10, "M10", 16, 12, 34, 0, 0, 0, 0, "add 40 weeks, ending in same year"
|
||||
);
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
date20000101.subtract(weeks40n),
|
||||
1999, 3, "M03", 16, 12, 34, 0, 0, 0, 0, "subtract 40 weeks, ending in previous year"
|
||||
);
|
||||
|
||||
@ -165,7 +183,8 @@ TemporalHelpers.assertPlainDateTime(
|
||||
|
||||
const days10 = new Temporal.Duration(0, 0, 0, /* days = */ -10);
|
||||
const days10n = new Temporal.Duration(0, 0, 0, 10);
|
||||
const days200 = new Temporal.Duration(0, 0, 0, /* days = */ 200);
|
||||
const days200 = new Temporal.Duration(0, 0, 0, /* days = */ -200);
|
||||
const days200n = new Temporal.Duration(0, 0, 0, 200);
|
||||
|
||||
const date20210129 = Temporal.PlainDateTime.from({ year: 2021, monthCode: "M01", day: 29, hour: 12, minute: 34, calendar }, options);
|
||||
|
||||
@ -201,5 +220,10 @@ TemporalHelpers.assertPlainDateTime(
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
date20000101.subtract(days200),
|
||||
2000, 7, "M07", 24, 12, 34, 0, 0, 0, 0, "add 200 days, ending in same year"
|
||||
);
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
date20000101.subtract(days200n),
|
||||
1999, 6, "M06", 8, 12, 34, 0, 0, 0, 0, "subtract 200 days, ending in previous year"
|
||||
);
|
||||
|
||||
@ -17,7 +17,8 @@ const years1 = new Temporal.Duration(-1);
|
||||
const years1n = new Temporal.Duration(1);
|
||||
const years5 = new Temporal.Duration(-5);
|
||||
const years5n = new Temporal.Duration(5);
|
||||
const years3months6days17 = new Temporal.Duration(3, 6, 0, 17);
|
||||
const years3months6days17 = new Temporal.Duration(-3, -6, 0, -17);
|
||||
const years3months6days17n = new Temporal.Duration(3, 6, 0, 17);
|
||||
|
||||
const date201802 = Temporal.PlainDateTime.from({ year: 2018, monthCode: "M02", day: 1, hour: 12, minute: 34, calendar }, options);
|
||||
const date202302 = Temporal.PlainDateTime.from({ year: 2023, monthCode: "M02", day: 29, hour: 12, minute: 34, calendar }, options);
|
||||
@ -65,6 +66,11 @@ TemporalHelpers.assertPlainDateTime(
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
date199712.subtract(years3months6days17),
|
||||
2001, 6, "M05", 18, 12, 34, 0, 0, 0, 0, "Adding 3 years/6 months/17 days to day 1 of a month"
|
||||
);
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
date199712.subtract(years3months6days17n),
|
||||
1994, 5, "M05", 14, 12, 34, 0, 0, 0, 0, "Subtracting 3 years/6 months/17 days from day 1 of a month"
|
||||
);
|
||||
|
||||
@ -74,7 +80,8 @@ const months1 = new Temporal.Duration(0, -1);
|
||||
const months1n = new Temporal.Duration(0, 1);
|
||||
const months4 = new Temporal.Duration(0, -4);
|
||||
const months4n = new Temporal.Duration(0, 4);
|
||||
const months6 = new Temporal.Duration(0, 6);
|
||||
const months6 = new Temporal.Duration(0, -6);
|
||||
const months6n = new Temporal.Duration(0, 6);
|
||||
|
||||
const date201901 = Temporal.PlainDateTime.from({ year: 2019, monthCode: "M01", day: 1, hour: 12, minute: 34, calendar }, options);
|
||||
const date201906 = Temporal.PlainDateTime.from({ year: 2019, monthCode: "M06", day: 1, hour: 12, minute: 34, calendar }, options);
|
||||
@ -124,6 +131,11 @@ TemporalHelpers.assertPlainDateTime(
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
date200012.subtract(months6),
|
||||
2001, 6, "M05", 1, 12, 34, 0, 0, 0, 0, "Adding 6 months, with result in next year (leap year)"
|
||||
);
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
date200012.subtract(months6n),
|
||||
2000, 6, "M06", 1, 12, 34, 0, 0, 0, 0, "Subtracting 6 months, with result in same year"
|
||||
);
|
||||
|
||||
@ -131,7 +143,8 @@ TemporalHelpers.assertPlainDateTime(
|
||||
|
||||
const months2weeks3 = new Temporal.Duration(0, /* months = */ -2, /* weeks = */ -3);
|
||||
const months2weeks3n = new Temporal.Duration(0, 2, 3);
|
||||
const weeks40 = new Temporal.Duration(0, 0, /* weeks = */ 40);
|
||||
const weeks40 = new Temporal.Duration(0, 0, /* weeks = */ -40);
|
||||
const weeks40n = new Temporal.Duration(0, 0, 40);
|
||||
|
||||
const date202101 = Temporal.PlainDateTime.from({ year: 2021, monthCode: "M01", day: 1, hour: 12, minute: 34, calendar }, options);
|
||||
const date20000101 = Temporal.PlainDateTime.from({ year: 2000, month: 1, day: 1, hour: 12, minute: 34, calendar }, options);
|
||||
@ -158,6 +171,11 @@ TemporalHelpers.assertPlainDateTime(
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
date20000101.subtract(weeks40),
|
||||
2000, 10, "M10", 16, 12, 34, 0, 0, 0, 0, "add 40 weeks, ending in same year"
|
||||
);
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
date20000101.subtract(weeks40n),
|
||||
1999, 3, "M03", 16, 12, 34, 0, 0, 0, 0, "subtract 40 weeks, ending in previous year"
|
||||
);
|
||||
|
||||
@ -165,7 +183,8 @@ TemporalHelpers.assertPlainDateTime(
|
||||
|
||||
const days10 = new Temporal.Duration(0, 0, 0, /* days = */ -10);
|
||||
const days10n = new Temporal.Duration(0, 0, 0, 10);
|
||||
const days200 = new Temporal.Duration(0, 0, 0, /* days = */ 200);
|
||||
const days200 = new Temporal.Duration(0, 0, 0, /* days = */ -200);
|
||||
const days200n = new Temporal.Duration(0, 0, 0, 200);
|
||||
|
||||
const date20210129 = Temporal.PlainDateTime.from({ year: 2021, monthCode: "M01", day: 29, hour: 12, minute: 34, calendar }, options);
|
||||
|
||||
@ -201,5 +220,10 @@ TemporalHelpers.assertPlainDateTime(
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
date20000101.subtract(days200),
|
||||
2000, 7, "M07", 24, 12, 34, 0, 0, 0, 0, "add 200 days, ending in same year"
|
||||
);
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
date20000101.subtract(days200n),
|
||||
1999, 6, "M06", 8, 12, 34, 0, 0, 0, 0, "subtract 200 days, ending in previous year"
|
||||
);
|
||||
|
||||
@ -18,6 +18,7 @@ const years1n = new Temporal.Duration(-1);
|
||||
const years5 = new Temporal.Duration(5);
|
||||
const years5n = new Temporal.Duration(-5);
|
||||
const years3months6days17 = new Temporal.Duration(3, 6, 0, 17);
|
||||
const years3months6days17n = new Temporal.Duration(-3, -6, 0, -17);
|
||||
|
||||
const date201802 = Temporal.ZonedDateTime.from({ year: 2018, monthCode: "M02", day: 1, hour: 12, minute: 34, timeZone: "UTC", calendar }, options);
|
||||
const date202302 = Temporal.ZonedDateTime.from({ year: 2023, monthCode: "M02", day: 29, hour: 12, minute: 34, timeZone: "UTC", calendar }, options);
|
||||
@ -68,6 +69,11 @@ TemporalHelpers.assertPlainDateTime(
|
||||
2001, 6, "M05", 18, 12, 34, 0, 0, 0, 0, "Adding 3 years/6 months/17 days to day 1 of a month"
|
||||
);
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
date199712.add(years3months6days17n).toPlainDateTime(),
|
||||
1994, 5, "M05", 14, 12, 34, 0, 0, 0, 0, "Subtracting 3 years/6 months/17 days from day 1 of a month"
|
||||
);
|
||||
|
||||
// Months
|
||||
|
||||
const months1 = new Temporal.Duration(0, 1);
|
||||
@ -75,6 +81,7 @@ const months1n = new Temporal.Duration(0, -1);
|
||||
const months4 = new Temporal.Duration(0, 4);
|
||||
const months4n = new Temporal.Duration(0, -4);
|
||||
const months6 = new Temporal.Duration(0, 6);
|
||||
const months6n = new Temporal.Duration(0, -6);
|
||||
|
||||
const date201901 = Temporal.ZonedDateTime.from({ year: 2019, monthCode: "M01", day: 1, hour: 12, minute: 34, timeZone: "UTC", calendar }, options);
|
||||
const date201906 = Temporal.ZonedDateTime.from({ year: 2019, monthCode: "M06", day: 1, hour: 12, minute: 34, timeZone: "UTC", calendar }, options);
|
||||
@ -127,11 +134,17 @@ TemporalHelpers.assertPlainDateTime(
|
||||
2001, 6, "M05", 1, 12, 34, 0, 0, 0, 0, "Adding 6 months, with result in next year (leap year)"
|
||||
);
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
date200012.add(months6n).toPlainDateTime(),
|
||||
2000, 6, "M06", 1, 12, 34, 0, 0, 0, 0, "Subtracting 6 months, with result in same year"
|
||||
);
|
||||
|
||||
// Weeks
|
||||
|
||||
const months2weeks3 = new Temporal.Duration(0, /* months = */ 2, /* weeks = */ 3);
|
||||
const months2weeks3n = new Temporal.Duration(0, -2, -3);
|
||||
const weeks40 = new Temporal.Duration(0, 0, /* weeks = */ 40);
|
||||
const weeks40n = new Temporal.Duration(0, 0, -40);
|
||||
|
||||
const date202101 = Temporal.ZonedDateTime.from({ year: 2021, monthCode: "M01", day: 1, hour: 12, minute: 34, timeZone: "UTC", calendar }, options);
|
||||
const date20000101 = Temporal.ZonedDateTime.from({ year: 2000, month: 1, day: 1, hour: 12, minute: 34, timeZone: "UTC", calendar }, options);
|
||||
@ -161,11 +174,17 @@ TemporalHelpers.assertPlainDateTime(
|
||||
2000, 10, "M10", 16, 12, 34, 0, 0, 0, 0, "add 40 weeks, ending in same year"
|
||||
);
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
date20000101.add(weeks40n).toPlainDateTime(),
|
||||
1999, 3, "M03", 16, 12, 34, 0, 0, 0, 0, "subtract 40 weeks, ending in previous year"
|
||||
);
|
||||
|
||||
// Days
|
||||
|
||||
const days10 = new Temporal.Duration(0, 0, 0, /* days = */ 10);
|
||||
const days10n = new Temporal.Duration(0, 0, 0, -10);
|
||||
const days200 = new Temporal.Duration(0, 0, 0, /* days = */ 200);
|
||||
const days200n = new Temporal.Duration(0, 0, 0, -200);
|
||||
|
||||
const date20210129 = Temporal.ZonedDateTime.from({ year: 2021, monthCode: "M01", day: 29, hour: 12, minute: 34, timeZone: "UTC", calendar }, options);
|
||||
|
||||
@ -203,3 +222,8 @@ TemporalHelpers.assertPlainDateTime(
|
||||
date20000101.add(days200).toPlainDateTime(),
|
||||
2000, 7, "M07", 24, 12, 34, 0, 0, 0, 0, "add 200 days, ending in same year"
|
||||
);
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
date20000101.add(days200n).toPlainDateTime(),
|
||||
1999, 6, "M06", 8, 12, 34, 0, 0, 0, 0, "subtract 200 days, ending in previous year"
|
||||
);
|
||||
|
||||
@ -18,6 +18,7 @@ const years1n = new Temporal.Duration(-1);
|
||||
const years5 = new Temporal.Duration(5);
|
||||
const years5n = new Temporal.Duration(-5);
|
||||
const years3months6days17 = new Temporal.Duration(3, 6, 0, 17);
|
||||
const years3months6days17n = new Temporal.Duration(-3, -6, 0, -17);
|
||||
|
||||
const date201802 = Temporal.ZonedDateTime.from({ year: 2018, monthCode: "M02", day: 1, hour: 12, minute: 34, timeZone: "UTC", calendar }, options);
|
||||
const date202302 = Temporal.ZonedDateTime.from({ year: 2023, monthCode: "M02", day: 29, hour: 12, minute: 34, timeZone: "UTC", calendar }, options);
|
||||
@ -68,6 +69,11 @@ TemporalHelpers.assertPlainDateTime(
|
||||
2001, 6, "M05", 18, 12, 34, 0, 0, 0, 0, "Adding 3 years/6 months/17 days to day 1 of a month"
|
||||
);
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
date199712.add(years3months6days17n).toPlainDateTime(),
|
||||
1994, 5, "M05", 14, 12, 34, 0, 0, 0, 0, "Subtracting 3 years/6 months/17 days from day 1 of a month"
|
||||
);
|
||||
|
||||
// Months
|
||||
|
||||
const months1 = new Temporal.Duration(0, 1);
|
||||
@ -75,6 +81,7 @@ const months1n = new Temporal.Duration(0, -1);
|
||||
const months4 = new Temporal.Duration(0, 4);
|
||||
const months4n = new Temporal.Duration(0, -4);
|
||||
const months6 = new Temporal.Duration(0, 6);
|
||||
const months6n = new Temporal.Duration(0, -6);
|
||||
|
||||
const date201901 = Temporal.ZonedDateTime.from({ year: 2019, monthCode: "M01", day: 1, hour: 12, minute: 34, timeZone: "UTC", calendar }, options);
|
||||
const date201906 = Temporal.ZonedDateTime.from({ year: 2019, monthCode: "M06", day: 1, hour: 12, minute: 34, timeZone: "UTC", calendar }, options);
|
||||
@ -127,11 +134,17 @@ TemporalHelpers.assertPlainDateTime(
|
||||
2001, 6, "M05", 1, 12, 34, 0, 0, 0, 0, "Adding 6 months, with result in next year (leap year)"
|
||||
);
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
date200012.add(months6n).toPlainDateTime(),
|
||||
2000, 6, "M06", 1, 12, 34, 0, 0, 0, 0, "Subtracting 6 months, with result in same year"
|
||||
);
|
||||
|
||||
// Weeks
|
||||
|
||||
const months2weeks3 = new Temporal.Duration(0, /* months = */ 2, /* weeks = */ 3);
|
||||
const months2weeks3n = new Temporal.Duration(0, -2, -3);
|
||||
const weeks40 = new Temporal.Duration(0, 0, /* weeks = */ 40);
|
||||
const weeks40n = new Temporal.Duration(0, 0, -40);
|
||||
|
||||
const date202101 = Temporal.ZonedDateTime.from({ year: 2021, monthCode: "M01", day: 1, hour: 12, minute: 34, timeZone: "UTC", calendar }, options);
|
||||
const date20000101 = Temporal.ZonedDateTime.from({ year: 2000, month: 1, day: 1, hour: 12, minute: 34, timeZone: "UTC", calendar }, options);
|
||||
@ -161,11 +174,17 @@ TemporalHelpers.assertPlainDateTime(
|
||||
2000, 10, "M10", 16, 12, 34, 0, 0, 0, 0, "add 40 weeks, ending in same year"
|
||||
);
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
date20000101.add(weeks40n).toPlainDateTime(),
|
||||
1999, 3, "M03", 16, 12, 34, 0, 0, 0, 0, "subtract 40 weeks, ending in previous year"
|
||||
);
|
||||
|
||||
// Days
|
||||
|
||||
const days10 = new Temporal.Duration(0, 0, 0, /* days = */ 10);
|
||||
const days10n = new Temporal.Duration(0, 0, 0, -10);
|
||||
const days200 = new Temporal.Duration(0, 0, 0, /* days = */ 200);
|
||||
const days200n = new Temporal.Duration(0, 0, 0, -200);
|
||||
|
||||
const date20210129 = Temporal.ZonedDateTime.from({ year: 2021, monthCode: "M01", day: 29, hour: 12, minute: 34, timeZone: "UTC", calendar }, options);
|
||||
|
||||
@ -203,3 +222,8 @@ TemporalHelpers.assertPlainDateTime(
|
||||
date20000101.add(days200).toPlainDateTime(),
|
||||
2000, 7, "M07", 24, 12, 34, 0, 0, 0, 0, "add 200 days, ending in same year"
|
||||
);
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
date20000101.add(days200n).toPlainDateTime(),
|
||||
1999, 6, "M06", 8, 12, 34, 0, 0, 0, 0, "subtract 200 days, ending in previous year"
|
||||
);
|
||||
|
||||
@ -17,7 +17,8 @@ const years1 = new Temporal.Duration(-1);
|
||||
const years1n = new Temporal.Duration(1);
|
||||
const years5 = new Temporal.Duration(-5);
|
||||
const years5n = new Temporal.Duration(5);
|
||||
const years3months6days17 = new Temporal.Duration(3, 6, 0, 17);
|
||||
const years3months6days17 = new Temporal.Duration(-3, -6, 0, -17);
|
||||
const years3months6days17n = new Temporal.Duration(3, 6, 0, 17);
|
||||
|
||||
const date201802 = Temporal.ZonedDateTime.from({ year: 2018, monthCode: "M02", day: 1, hour: 12, minute: 34, timeZone: "UTC", calendar }, options);
|
||||
const date202302 = Temporal.ZonedDateTime.from({ year: 2023, monthCode: "M02", day: 29, hour: 12, minute: 34, timeZone: "UTC", calendar }, options);
|
||||
@ -65,6 +66,11 @@ TemporalHelpers.assertPlainDateTime(
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
date199712.subtract(years3months6days17).toPlainDateTime(),
|
||||
2001, 6, "M05", 18, 12, 34, 0, 0, 0, 0, "Adding 3 years/6 months/17 days to day 1 of a month"
|
||||
);
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
date199712.subtract(years3months6days17n).toPlainDateTime(),
|
||||
1994, 5, "M05", 14, 12, 34, 0, 0, 0, 0, "Subtracting 3 years/6 months/17 days from day 1 of a month"
|
||||
);
|
||||
|
||||
@ -74,7 +80,8 @@ const months1 = new Temporal.Duration(0, -1);
|
||||
const months1n = new Temporal.Duration(0, 1);
|
||||
const months4 = new Temporal.Duration(0, -4);
|
||||
const months4n = new Temporal.Duration(0, 4);
|
||||
const months6 = new Temporal.Duration(0, 6);
|
||||
const months6 = new Temporal.Duration(0, -6);
|
||||
const months6n = new Temporal.Duration(0, 6);
|
||||
|
||||
const date201901 = Temporal.ZonedDateTime.from({ year: 2019, monthCode: "M01", day: 1, hour: 12, minute: 34, timeZone: "UTC", calendar }, options);
|
||||
const date201906 = Temporal.ZonedDateTime.from({ year: 2019, monthCode: "M06", day: 1, hour: 12, minute: 34, timeZone: "UTC", calendar }, options);
|
||||
@ -124,6 +131,11 @@ TemporalHelpers.assertPlainDateTime(
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
date200012.subtract(months6).toPlainDateTime(),
|
||||
2001, 6, "M05", 1, 12, 34, 0, 0, 0, 0, "Adding 6 months, with result in next year (leap year)"
|
||||
);
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
date200012.subtract(months6n).toPlainDateTime(),
|
||||
2000, 6, "M06", 1, 12, 34, 0, 0, 0, 0, "Subtracting 6 months, with result in same year"
|
||||
);
|
||||
|
||||
@ -131,7 +143,8 @@ TemporalHelpers.assertPlainDateTime(
|
||||
|
||||
const months2weeks3 = new Temporal.Duration(0, /* months = */ -2, /* weeks = */ -3);
|
||||
const months2weeks3n = new Temporal.Duration(0, 2, 3);
|
||||
const weeks40 = new Temporal.Duration(0, 0, /* weeks = */ 40);
|
||||
const weeks40 = new Temporal.Duration(0, 0, /* weeks = */ -40);
|
||||
const weeks40n = new Temporal.Duration(0, 0, 40);
|
||||
|
||||
const date202101 = Temporal.ZonedDateTime.from({ year: 2021, monthCode: "M01", day: 1, hour: 12, minute: 34, timeZone: "UTC", calendar }, options);
|
||||
const date20000101 = Temporal.ZonedDateTime.from({ year: 2000, month: 1, day: 1, hour: 12, minute: 34, timeZone: "UTC", calendar }, options);
|
||||
@ -158,6 +171,11 @@ TemporalHelpers.assertPlainDateTime(
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
date20000101.subtract(weeks40).toPlainDateTime(),
|
||||
2000, 10, "M10", 16, 12, 34, 0, 0, 0, 0, "add 40 weeks, ending in same year"
|
||||
);
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
date20000101.subtract(weeks40n).toPlainDateTime(),
|
||||
1999, 3, "M03", 16, 12, 34, 0, 0, 0, 0, "subtract 40 weeks, ending in previous year"
|
||||
);
|
||||
|
||||
@ -165,7 +183,8 @@ TemporalHelpers.assertPlainDateTime(
|
||||
|
||||
const days10 = new Temporal.Duration(0, 0, 0, /* days = */ -10);
|
||||
const days10n = new Temporal.Duration(0, 0, 0, 10);
|
||||
const days200 = new Temporal.Duration(0, 0, 0, /* days = */ 200);
|
||||
const days200 = new Temporal.Duration(0, 0, 0, /* days = */ -200);
|
||||
const days200n = new Temporal.Duration(0, 0, 0, 200);
|
||||
|
||||
const date20210129 = Temporal.ZonedDateTime.from({ year: 2021, monthCode: "M01", day: 29, hour: 12, minute: 34, timeZone: "UTC", calendar }, options);
|
||||
|
||||
@ -201,5 +220,10 @@ TemporalHelpers.assertPlainDateTime(
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
date20000101.subtract(days200).toPlainDateTime(),
|
||||
2000, 7, "M07", 24, 12, 34, 0, 0, 0, 0, "add 200 days, ending in same year"
|
||||
);
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
date20000101.subtract(days200n).toPlainDateTime(),
|
||||
1999, 6, "M06", 8, 12, 34, 0, 0, 0, 0, "subtract 200 days, ending in previous year"
|
||||
);
|
||||
|
||||
@ -17,7 +17,8 @@ const years1 = new Temporal.Duration(-1);
|
||||
const years1n = new Temporal.Duration(1);
|
||||
const years5 = new Temporal.Duration(-5);
|
||||
const years5n = new Temporal.Duration(5);
|
||||
const years3months6days17 = new Temporal.Duration(3, 6, 0, 17);
|
||||
const years3months6days17 = new Temporal.Duration(-3, -6, 0, -17);
|
||||
const years3months6days17n = new Temporal.Duration(3, 6, 0, 17);
|
||||
|
||||
const date201802 = Temporal.ZonedDateTime.from({ year: 2018, monthCode: "M02", day: 1, hour: 12, minute: 34, timeZone: "UTC", calendar }, options);
|
||||
const date202302 = Temporal.ZonedDateTime.from({ year: 2023, monthCode: "M02", day: 29, hour: 12, minute: 34, timeZone: "UTC", calendar }, options);
|
||||
@ -65,6 +66,11 @@ TemporalHelpers.assertPlainDateTime(
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
date199712.subtract(years3months6days17).toPlainDateTime(),
|
||||
2001, 6, "M05", 18, 12, 34, 0, 0, 0, 0, "Adding 3 years/6 months/17 days to day 1 of a month"
|
||||
);
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
date199712.subtract(years3months6days17n).toPlainDateTime(),
|
||||
1994, 5, "M05", 14, 12, 34, 0, 0, 0, 0, "Subtracting 3 years/6 months/17 days from day 1 of a month"
|
||||
);
|
||||
|
||||
@ -74,7 +80,8 @@ const months1 = new Temporal.Duration(0, -1);
|
||||
const months1n = new Temporal.Duration(0, 1);
|
||||
const months4 = new Temporal.Duration(0, -4);
|
||||
const months4n = new Temporal.Duration(0, 4);
|
||||
const months6 = new Temporal.Duration(0, 6);
|
||||
const months6 = new Temporal.Duration(0, -6);
|
||||
const months6n = new Temporal.Duration(0, 6);
|
||||
|
||||
const date201901 = Temporal.ZonedDateTime.from({ year: 2019, monthCode: "M01", day: 1, hour: 12, minute: 34, timeZone: "UTC", calendar }, options);
|
||||
const date201906 = Temporal.ZonedDateTime.from({ year: 2019, monthCode: "M06", day: 1, hour: 12, minute: 34, timeZone: "UTC", calendar }, options);
|
||||
@ -124,6 +131,11 @@ TemporalHelpers.assertPlainDateTime(
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
date200012.subtract(months6).toPlainDateTime(),
|
||||
2001, 6, "M05", 1, 12, 34, 0, 0, 0, 0, "Adding 6 months, with result in next year (leap year)"
|
||||
);
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
date200012.subtract(months6n).toPlainDateTime(),
|
||||
2000, 6, "M06", 1, 12, 34, 0, 0, 0, 0, "Subtracting 6 months, with result in same year"
|
||||
);
|
||||
|
||||
@ -131,7 +143,8 @@ TemporalHelpers.assertPlainDateTime(
|
||||
|
||||
const months2weeks3 = new Temporal.Duration(0, /* months = */ -2, /* weeks = */ -3);
|
||||
const months2weeks3n = new Temporal.Duration(0, 2, 3);
|
||||
const weeks40 = new Temporal.Duration(0, 0, /* weeks = */ 40);
|
||||
const weeks40 = new Temporal.Duration(0, 0, /* weeks = */ -40);
|
||||
const weeks40n = new Temporal.Duration(0, 0, 40);
|
||||
|
||||
const date202101 = Temporal.ZonedDateTime.from({ year: 2021, monthCode: "M01", day: 1, hour: 12, minute: 34, timeZone: "UTC", calendar }, options);
|
||||
const date20000101 = Temporal.ZonedDateTime.from({ year: 2000, month: 1, day: 1, hour: 12, minute: 34, timeZone: "UTC", calendar }, options);
|
||||
@ -158,6 +171,11 @@ TemporalHelpers.assertPlainDateTime(
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
date20000101.subtract(weeks40).toPlainDateTime(),
|
||||
2000, 10, "M10", 16, 12, 34, 0, 0, 0, 0, "add 40 weeks, ending in same year"
|
||||
);
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
date20000101.subtract(weeks40n).toPlainDateTime(),
|
||||
1999, 3, "M03", 16, 12, 34, 0, 0, 0, 0, "subtract 40 weeks, ending in previous year"
|
||||
);
|
||||
|
||||
@ -165,7 +183,8 @@ TemporalHelpers.assertPlainDateTime(
|
||||
|
||||
const days10 = new Temporal.Duration(0, 0, 0, /* days = */ -10);
|
||||
const days10n = new Temporal.Duration(0, 0, 0, 10);
|
||||
const days200 = new Temporal.Duration(0, 0, 0, /* days = */ 200);
|
||||
const days200 = new Temporal.Duration(0, 0, 0, /* days = */ -200);
|
||||
const days200n = new Temporal.Duration(0, 0, 0, 200);
|
||||
|
||||
const date20210129 = Temporal.ZonedDateTime.from({ year: 2021, monthCode: "M01", day: 29, hour: 12, minute: 34, timeZone: "UTC", calendar }, options);
|
||||
|
||||
@ -201,5 +220,10 @@ TemporalHelpers.assertPlainDateTime(
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
date20000101.subtract(days200).toPlainDateTime(),
|
||||
2000, 7, "M07", 24, 12, 34, 0, 0, 0, 0, "add 200 days, ending in same year"
|
||||
);
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
date20000101.subtract(days200n).toPlainDateTime(),
|
||||
1999, 6, "M06", 8, 12, 34, 0, 0, 0, 0, "subtract 200 days, ending in previous year"
|
||||
);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user