|
| 1 | +// Copyright (C) 2025 Igalia, S.L. All rights reserved. |
| 2 | +// This code is governed by the BSD license found in the LICENSE file. |
| 3 | + |
| 4 | +/*--- |
| 5 | +esid: sec-temporal.plaindate.prototype.with |
| 6 | +description: Check constraining days to the end of a month (buddhist calendar) |
| 7 | +features: [Temporal] |
| 8 | +includes: [temporalHelpers.js] |
| 9 | +---*/ |
| 10 | + |
| 11 | +const calendar = "buddhist"; |
| 12 | +const options = { overflow: "reject" }; |
| 13 | + |
| 14 | +const common0131 = Temporal.PlainDate.from({ year: 2562, monthCode: "M01", day: 31, calendar }, options); |
| 15 | +const leap0131 = Temporal.PlainDate.from({ year: 2559, monthCode: "M01", day: 31, calendar }, options); |
| 16 | + |
| 17 | +// Common year |
| 18 | + |
| 19 | +TemporalHelpers.assertPlainDate( |
| 20 | + common0131.with({ monthCode: "M02" }), |
| 21 | + 2562, 2, "M02", 28, "common-year Feb constrains to 28", |
| 22 | + "be", 2562); |
| 23 | +assert.throws(RangeError, function () { |
| 24 | + common0131.with({ monthCode: "M02" }, options); |
| 25 | +}, "common-year Feb rejects with 31"); |
| 26 | + |
| 27 | +TemporalHelpers.assertPlainDate( |
| 28 | + common0131.with({ monthCode: "M03" }, options), |
| 29 | + 2562, 3, "M03", 31, "common-year Mar does not reject 31", |
| 30 | + "be", 2562); |
| 31 | + |
| 32 | +TemporalHelpers.assertPlainDate( |
| 33 | + common0131.with({ monthCode: "M04" }), |
| 34 | + 2562, 4, "M04", 30, "common-year Apr constrains to 30", |
| 35 | + "be", 2562); |
| 36 | +assert.throws(RangeError, function () { |
| 37 | + common0131.with({ monthCode: "M04" }, options); |
| 38 | +}, "common-year Apr rejects with 31"); |
| 39 | + |
| 40 | +TemporalHelpers.assertPlainDate( |
| 41 | + common0131.with({ monthCode: "M05" }, options), |
| 42 | + 2562, 5, "M05", 31, "common-year May does not reject 31", |
| 43 | + "be", 2562); |
| 44 | + |
| 45 | +TemporalHelpers.assertPlainDate( |
| 46 | + common0131.with({ monthCode: "M06" }), |
| 47 | + 2562, 6, "M06", 30, "common-year Jun constrains to 30", |
| 48 | + "be", 2562); |
| 49 | +assert.throws(RangeError, function () { |
| 50 | + common0131.with({ monthCode: "M06" }, options); |
| 51 | +}, "common-year Jun rejects with 31"); |
| 52 | + |
| 53 | +TemporalHelpers.assertPlainDate( |
| 54 | + common0131.with({ monthCode: "M07" }, options), |
| 55 | + 2562, 7, "M07", 31, "common-year Jul does not reject 31", |
| 56 | + "be", 2562); |
| 57 | + |
| 58 | +TemporalHelpers.assertPlainDate( |
| 59 | + common0131.with({ monthCode: "M08" }, options), |
| 60 | + 2562, 8, "M08", 31, "common-year Aug does not reject 31", |
| 61 | + "be", 2562); |
| 62 | + |
| 63 | +TemporalHelpers.assertPlainDate( |
| 64 | + common0131.with({ monthCode: "M09" }), |
| 65 | + 2562, 9, "M09", 30, "common-year Sep constrains to 30", |
| 66 | + "be", 2562); |
| 67 | +assert.throws(RangeError, function () { |
| 68 | + common0131.with({ monthCode: "M09" }, options); |
| 69 | +}, "common-year Sep rejects with 31"); |
| 70 | + |
| 71 | +TemporalHelpers.assertPlainDate( |
| 72 | + common0131.with({ monthCode: "M10" }, options), |
| 73 | + 2562, 10, "M10", 31, "common-year Oct does not reject 31", |
| 74 | + "be", 2562); |
| 75 | + |
| 76 | +TemporalHelpers.assertPlainDate( |
| 77 | + common0131.with({ monthCode: "M11" }), |
| 78 | + 2562, 11, "M11", 30, "common-year Nov constrains to 30", |
| 79 | + "be", 2562); |
| 80 | +assert.throws(RangeError, function () { |
| 81 | + common0131.with({ monthCode: "M11" }, options); |
| 82 | +}, "common-year Nov rejects with 31"); |
| 83 | + |
| 84 | +TemporalHelpers.assertPlainDate( |
| 85 | + common0131.with({ monthCode: "M12" }, options), |
| 86 | + 2562, 12, "M12", 31, "common-year Dec does not reject 31", |
| 87 | + "be", 2562); |
| 88 | + |
| 89 | +// Leap year, forwards |
| 90 | + |
| 91 | +TemporalHelpers.assertPlainDate( |
| 92 | + leap0131.with({ monthCode: "M02" }), |
| 93 | + 2559, 2, "M02", 29, "leap-year Feb constrains to 29", |
| 94 | + "be", 2559); |
| 95 | +assert.throws(RangeError, function () { |
| 96 | + leap0131.with({ monthCode: "M02" }, options); |
| 97 | +}, "leap-year Feb rejects with 31"); |
| 98 | + |
| 99 | +TemporalHelpers.assertPlainDate( |
| 100 | + leap0131.with({ monthCode: "M03" }, options), |
| 101 | + 2559, 3, "M03", 31, "leap-year Mar does not reject 31", |
| 102 | + "be", 2559); |
| 103 | + |
| 104 | +TemporalHelpers.assertPlainDate( |
| 105 | + leap0131.with({ monthCode: "M04" }), |
| 106 | + 2559, 4, "M04", 30, "leap-year Apr constrains to 30", |
| 107 | + "be", 2559); |
| 108 | +assert.throws(RangeError, function () { |
| 109 | + leap0131.with({ monthCode: "M04" }, options); |
| 110 | +}, "leap-year Apr rejects with 31"); |
| 111 | + |
| 112 | +TemporalHelpers.assertPlainDate( |
| 113 | + leap0131.with({ monthCode: "M05" }, options), |
| 114 | + 2559, 5, "M05", 31, "leap-year May does not reject 31", |
| 115 | + "be", 2559); |
| 116 | + |
| 117 | +TemporalHelpers.assertPlainDate( |
| 118 | + leap0131.with({ monthCode: "M06" }), |
| 119 | + 2559, 6, "M06", 30, "leap-year Jun constrains to 30", |
| 120 | + "be", 2559); |
| 121 | +assert.throws(RangeError, function () { |
| 122 | + leap0131.with({ monthCode: "M06" }, options); |
| 123 | +}, "leap-year Jun rejects with 31"); |
| 124 | + |
| 125 | +TemporalHelpers.assertPlainDate( |
| 126 | + leap0131.with({ monthCode: "M07" }, options), |
| 127 | + 2559, 7, "M07", 31, "leap-year Jul does not reject 31", |
| 128 | + "be", 2559); |
| 129 | + |
| 130 | +TemporalHelpers.assertPlainDate( |
| 131 | + leap0131.with({ monthCode: "M08" }, options), |
| 132 | + 2559, 8, "M08", 31, "leap-year Aug does not reject 31", |
| 133 | + "be", 2559); |
| 134 | + |
| 135 | +TemporalHelpers.assertPlainDate( |
| 136 | + leap0131.with({ monthCode: "M09" }), |
| 137 | + 2559, 9, "M09", 30, "leap-year Sep constrains to 30", |
| 138 | + "be", 2559); |
| 139 | +assert.throws(RangeError, function () { |
| 140 | + leap0131.with({ monthCode: "M09" }, options); |
| 141 | +}, "leap-year Sep rejects with 31"); |
| 142 | + |
| 143 | +TemporalHelpers.assertPlainDate( |
| 144 | + leap0131.with({ monthCode: "M10" }, options), |
| 145 | + 2559, 10, "M10", 31, "leap-year Oct does not reject 31", |
| 146 | + "be", 2559); |
| 147 | + |
| 148 | +TemporalHelpers.assertPlainDate( |
| 149 | + leap0131.with({ monthCode: "M11" }), |
| 150 | + 2559, 11, "M11", 30, "leap-year Nov constrains to 30", |
| 151 | + "be", 2559); |
| 152 | +assert.throws(RangeError, function () { |
| 153 | + leap0131.with({ monthCode: "M11" }, options); |
| 154 | +}, "leap-year Nov rejects with 31"); |
| 155 | + |
| 156 | +TemporalHelpers.assertPlainDate( |
| 157 | + leap0131.with({ monthCode: "M12" }, options), |
| 158 | + 2559, 12, "M12", 31, "leap-year Dec does not reject 31", |
| 159 | + "be", 2559); |
0 commit comments