|
| 1 | +// Copyright (C) 2026 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-partitiondatetimerangepattern |
| 6 | +description: TimeClip is not applied for Temporal plain objects. |
| 7 | +info: | |
| 8 | + PartitionDateTimeRangePattern ( _dateTimeFormat_, _x_, _y_ ) |
| 9 | + 2. Let _xFormatRecord_ be ? ValueFormatRecord(_dateTimeFormat_, _x_). |
| 10 | + 3. Let _yFormatRecord_ be ? ValueFormatRecord(_dateTimeFormat_, _y_). |
| 11 | +features: [Temporal] |
| 12 | +locale: [en] |
| 13 | +---*/ |
| 14 | + |
| 15 | +// Based on the test in |
| 16 | +// DateTime/prototype/format/temporal-objects-no-time-clip.js by André Bargull. |
| 17 | + |
| 18 | +function findPart(parts, expectedType, expectedSource) { |
| 19 | + return parts.find(({ type, source }) => type === expectedType && source === expectedSource).value; |
| 20 | +} |
| 21 | + |
| 22 | +// Test with Temporal default calendar "iso8601" and additionally "gregory". |
| 23 | +var calendars = ["iso8601", "gregory"]; |
| 24 | + |
| 25 | +for (var calendar of calendars) { |
| 26 | + var dtf = new Intl.DateTimeFormat("en", {calendar}); |
| 27 | + |
| 28 | + // Minimum and maximum PlainDate values |
| 29 | + var minDate = new Temporal.PlainDate(-271821, 4, 19, calendar); |
| 30 | + var maxDate = new Temporal.PlainDate(275760, 9, 13, calendar); |
| 31 | + var dateParts = dtf.formatRangeToParts(minDate, maxDate); |
| 32 | + var yearPart = +findPart(dateParts, "year", "startRange"); |
| 33 | + assert(yearPart === -271821 || yearPart === 271822, "dateParts includes min year"); |
| 34 | + assert.sameValue(+findPart(dateParts, "month", "startRange"), 4, "dateParts includes min month"); |
| 35 | + assert.sameValue(+findPart(dateParts, "day", "startRange"), 19, "dateParts includes min day"); |
| 36 | + assert.sameValue(+findPart(dateParts, "year", "endRange"), 275760, "dateParts includes max year"); |
| 37 | + assert.sameValue(+findPart(dateParts, "month", "endRange"), 9, "dateParts includes max month"); |
| 38 | + assert.sameValue(+findPart(dateParts, "day", "endRange"), 13, "dateParts includes max day"); |
| 39 | + |
| 40 | + // Minimum and maximum PlainDateTime values |
| 41 | + var minDateTime = new Temporal.PlainDateTime(-271821, 4, 19, 0, 0, 0, 0, 0, 1, calendar); |
| 42 | + var maxDateTime = new Temporal.PlainDateTime(275760, 9, 13, 23, 59, 59, 999, 999, 999, calendar); |
| 43 | + var dateTimeParts = dtf.formatRangeToParts(minDateTime, maxDateTime); |
| 44 | + yearPart = +findPart(dateTimeParts, "year", "startRange"); |
| 45 | + assert(yearPart === -271821 || yearPart === 271822, "dateTimeParts includes min year"); |
| 46 | + assert.sameValue(+findPart(dateTimeParts, "month", "startRange"), 4, "dateTimeParts includes min month"); |
| 47 | + assert.sameValue(+findPart(dateTimeParts, "day", "startRange"), 19, "dateTimeParts includes min day"); |
| 48 | + assert.sameValue(+findPart(dateTimeParts, "year", "endRange"), 275760, "dateTimeParts includes max year"); |
| 49 | + assert.sameValue(+findPart(dateTimeParts, "month", "endRange"), 9, "dateTimeParts includes max month"); |
| 50 | + assert.sameValue(+findPart(dateTimeParts, "day", "endRange"), 13, "dateTimeParts includes max day"); |
| 51 | + |
| 52 | + // Minimum and maximum PlainYearMonth values |
| 53 | + var minYearMonth = new Temporal.PlainYearMonth(-271821, 4, calendar); |
| 54 | + var maxYearMonth = new Temporal.PlainYearMonth(275760, 9, calendar); |
| 55 | + var yearMonthParts = dtf.formatRangeToParts(minYearMonth, maxYearMonth); |
| 56 | + yearPart = +findPart(yearMonthParts, "year", "startRange"); |
| 57 | + assert(yearPart === -271821 || yearPart === 271822, "yearMonthParts includes min year"); |
| 58 | + assert.sameValue(+findPart(yearMonthParts, "month", "startRange"), 4, "yearMonthParts includes min month"); |
| 59 | + assert.sameValue(+findPart(yearMonthParts, "year", "endRange"), 275760, "yearMonthParts includes max year"); |
| 60 | + assert.sameValue(+findPart(yearMonthParts, "month", "endRange"), 9, "yearMonthParts includes max month"); |
| 61 | +} |
0 commit comments