diff --git a/test/intl402/Temporal/PlainDate/prototype/add/basic-chinese.js b/test/intl402/Temporal/PlainDate/prototype/add/basic-chinese.js index a2cad14558..b4627387ff 100644 --- a/test/intl402/Temporal/PlainDate/prototype/add/basic-chinese.js +++ b/test/intl402/Temporal/PlainDate/prototype/add/basic-chinese.js @@ -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" +); diff --git a/test/intl402/Temporal/PlainDate/prototype/add/basic-dangi.js b/test/intl402/Temporal/PlainDate/prototype/add/basic-dangi.js index c209dee227..e2b0692d9e 100644 --- a/test/intl402/Temporal/PlainDate/prototype/add/basic-dangi.js +++ b/test/intl402/Temporal/PlainDate/prototype/add/basic-dangi.js @@ -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" +); diff --git a/test/intl402/Temporal/PlainDate/prototype/subtract/basic-chinese.js b/test/intl402/Temporal/PlainDate/prototype/subtract/basic-chinese.js index 3379061f0e..2a9b02732a 100644 --- a/test/intl402/Temporal/PlainDate/prototype/subtract/basic-chinese.js +++ b/test/intl402/Temporal/PlainDate/prototype/subtract/basic-chinese.js @@ -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" ); diff --git a/test/intl402/Temporal/PlainDate/prototype/subtract/basic-dangi.js b/test/intl402/Temporal/PlainDate/prototype/subtract/basic-dangi.js index f0d6d50264..421b20db71 100644 --- a/test/intl402/Temporal/PlainDate/prototype/subtract/basic-dangi.js +++ b/test/intl402/Temporal/PlainDate/prototype/subtract/basic-dangi.js @@ -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" ); diff --git a/test/intl402/Temporal/PlainDateTime/prototype/add/basic-chinese.js b/test/intl402/Temporal/PlainDateTime/prototype/add/basic-chinese.js index b44446ee02..93f43edba7 100644 --- a/test/intl402/Temporal/PlainDateTime/prototype/add/basic-chinese.js +++ b/test/intl402/Temporal/PlainDateTime/prototype/add/basic-chinese.js @@ -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" +); diff --git a/test/intl402/Temporal/PlainDateTime/prototype/add/basic-dangi.js b/test/intl402/Temporal/PlainDateTime/prototype/add/basic-dangi.js index bde8805d0a..e933b360f2 100644 --- a/test/intl402/Temporal/PlainDateTime/prototype/add/basic-dangi.js +++ b/test/intl402/Temporal/PlainDateTime/prototype/add/basic-dangi.js @@ -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" +); diff --git a/test/intl402/Temporal/PlainDateTime/prototype/subtract/basic-chinese.js b/test/intl402/Temporal/PlainDateTime/prototype/subtract/basic-chinese.js index 6cd5fca186..1a2c7b65c4 100644 --- a/test/intl402/Temporal/PlainDateTime/prototype/subtract/basic-chinese.js +++ b/test/intl402/Temporal/PlainDateTime/prototype/subtract/basic-chinese.js @@ -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" ); diff --git a/test/intl402/Temporal/PlainDateTime/prototype/subtract/basic-dangi.js b/test/intl402/Temporal/PlainDateTime/prototype/subtract/basic-dangi.js index 6ff353fc21..a09fcfe3bf 100644 --- a/test/intl402/Temporal/PlainDateTime/prototype/subtract/basic-dangi.js +++ b/test/intl402/Temporal/PlainDateTime/prototype/subtract/basic-dangi.js @@ -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" ); diff --git a/test/intl402/Temporal/ZonedDateTime/prototype/add/basic-chinese.js b/test/intl402/Temporal/ZonedDateTime/prototype/add/basic-chinese.js index 6a530fc5d4..32cf47abcc 100644 --- a/test/intl402/Temporal/ZonedDateTime/prototype/add/basic-chinese.js +++ b/test/intl402/Temporal/ZonedDateTime/prototype/add/basic-chinese.js @@ -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" +); diff --git a/test/intl402/Temporal/ZonedDateTime/prototype/add/basic-dangi.js b/test/intl402/Temporal/ZonedDateTime/prototype/add/basic-dangi.js index 2cfa75b891..7fc8b6a539 100644 --- a/test/intl402/Temporal/ZonedDateTime/prototype/add/basic-dangi.js +++ b/test/intl402/Temporal/ZonedDateTime/prototype/add/basic-dangi.js @@ -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" +); diff --git a/test/intl402/Temporal/ZonedDateTime/prototype/subtract/basic-chinese.js b/test/intl402/Temporal/ZonedDateTime/prototype/subtract/basic-chinese.js index 0fe30a2880..d80a752407 100644 --- a/test/intl402/Temporal/ZonedDateTime/prototype/subtract/basic-chinese.js +++ b/test/intl402/Temporal/ZonedDateTime/prototype/subtract/basic-chinese.js @@ -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" ); diff --git a/test/intl402/Temporal/ZonedDateTime/prototype/subtract/basic-dangi.js b/test/intl402/Temporal/ZonedDateTime/prototype/subtract/basic-dangi.js index 6fa874e91c..68c31c159e 100644 --- a/test/intl402/Temporal/ZonedDateTime/prototype/subtract/basic-dangi.js +++ b/test/intl402/Temporal/ZonedDateTime/prototype/subtract/basic-dangi.js @@ -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" );