Debian Codegraph @

js/src/tests/test262/intl402/DateTimeFormat/constructor-options-timeStyle-valid.js

raw
1 // Copyright 2019 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-createdatetimeformat
6 description: >
7 Checks handling of the options argument to the DateTimeFormat constructor.
8 info: |
9 CreateDateTimeFormat ( dateTimeFormat, locales, options, required, default )
10
11 ...
12 41. Let timeStyle be ? GetOption(options, "timeStyle", string, « "full", "long", "medium", "short" », undefined).
13 42. Set dateTimeFormat.[[TimeStyle]] to timeStyle.
14 features: [Intl.DateTimeFormat-datetimestyle]
15 ---*/
16
17 const validOptions = [
18 [undefined, undefined],
19 ["full", "full"],
20 ["long", "long"],
21 ["medium", "medium"],
22 ["short", "short"],
23 [{ toString() { return "full"; } }, "full"],
24 [{ valueOf() { return "long"; }, toString: undefined }, "long"],
25 ];
26 for (const [timeStyle, expected] of validOptions) {
27 const dtf = new Intl.DateTimeFormat("en", { timeStyle });
28 const options = dtf.resolvedOptions();
29 assert.sameValue(options.timeStyle, expected);
30 const propdesc = Object.getOwnPropertyDescriptor(options, "timeStyle");
31 if (expected === undefined) {
32 assert.sameValue(propdesc, undefined);
33 } else {
34 assert.sameValue(propdesc.value, expected);
35 }
36 }
37
38 reportCompare(0, 0);