| 1 |
// Copyright 2021 Kate Miháliková. All rights reserved. |
| 2 |
// This code is governed by the BSD license found in the LICENSE file. |
| 3 |
|
| 4 |
/*--- |
| 5 |
esid: sec-createdatetimeformat |
| 6 |
description: > |
| 7 |
Conflicting properties of dateStyle/timeStyle must be rejected with a TypeError for the options argument to the DateTimeFormat constructor. |
| 8 |
info: | |
| 9 |
InitializeDateTimeFormat ( dateTimeFormat, locales, options ) |
| 10 |
|
| 11 |
... |
| 12 |
43. If dateStyle is not undefined or timeStyle is not undefined, then |
| 13 |
a. If hasExplicitFormatComponents is true, then |
| 14 |
i. Throw a TypeError exception. |
| 15 |
b. If required is date and timeStyle is not undefined, then |
| 16 |
i. Throw a TypeError exception. |
| 17 |
c. If required is time and dateStyle is not undefined, then |
| 18 |
i. Throw a TypeError exception. |
| 19 |
---*/ |
| 20 |
|
| 21 |
|
| 22 |
// Table 4 - Property column + example value from Values column |
| 23 |
const conflictingOptions = [ |
| 24 |
[ "weekday", "short" ], |
| 25 |
[ "era", "short" ], |
| 26 |
[ "year", "numeric" ], |
| 27 |
[ "month", "numeric" ], |
| 28 |
[ "day", "numeric" ], |
| 29 |
[ "dayPeriod", "short" ], |
| 30 |
[ "hour", "numeric" ], |
| 31 |
[ "minute", "numeric" ], |
| 32 |
[ "second", "numeric" ], |
| 33 |
[ "fractionalSecondDigits", 3 ], |
| 34 |
[ "timeZoneName", "short" ], |
| 35 |
]; |
| 36 |
|
| 37 |
for (const [ option, value ] of conflictingOptions) { |
| 38 |
assert.throws(TypeError, function() { |
| 39 |
new Intl.DateTimeFormat("en", { [option]: value, dateStyle: "short" }); |
| 40 |
}, `new Intl.DateTimeFormat("en", { ${option}: "${value}", dateStyle: "short" }) throws TypeError`); |
| 41 |
|
| 42 |
assert.throws(TypeError, function() { |
| 43 |
new Intl.DateTimeFormat("en", { [option]: value, timeStyle: "short" }); |
| 44 |
}, `new Intl.DateTimeFormat("en", { ${option}: "${value}", timeStyle: "short" }) throws TypeError`); |
| 45 |
} |
| 46 |
|
| 47 |
reportCompare(0, 0); |