2020-04-23 05:08:13 +00:00
|
|
|
// Copyright 2020 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2020-07-10 01:22:05 +00:00
|
|
|
assertThrows(
|
|
|
|
() => (new Intl.DateTimeFormat("en", {fractionalSecondDigits: 0})),
|
|
|
|
RangeError,
|
|
|
|
"fractionalSecondDigits value is out of range.");
|
|
|
|
|
|
|
|
assertThrows(
|
|
|
|
() => (new Intl.DateTimeFormat("en", {fractionalSecondDigits: 4})),
|
|
|
|
RangeError,
|
|
|
|
"fractionalSecondDigits value is out of range.");
|
2020-04-23 05:08:13 +00:00
|
|
|
|
|
|
|
assertEquals(
|
|
|
|
1,
|
|
|
|
(new Intl.DateTimeFormat("en", {fractionalSecondDigits: 1}))
|
|
|
|
.resolvedOptions().fractionalSecondDigits);
|
|
|
|
|
|
|
|
assertEquals(
|
|
|
|
2,
|
|
|
|
(new Intl.DateTimeFormat("en", {fractionalSecondDigits: 2}))
|
|
|
|
.resolvedOptions().fractionalSecondDigits);
|
|
|
|
|
|
|
|
assertEquals(
|
|
|
|
3,
|
|
|
|
(new Intl.DateTimeFormat("en", {fractionalSecondDigits: 3}))
|
|
|
|
.resolvedOptions().fractionalSecondDigits);
|
|
|
|
|
|
|
|
// When timeStyle and dateStyle is not present, GetNumberOption will fallback
|
2020-07-09 22:18:10 +00:00
|
|
|
// to undefined as default regardless fractionalSecondDigits is present in the option or
|
2020-04-23 05:08:13 +00:00
|
|
|
// not.
|
|
|
|
assertEquals(
|
2020-07-09 22:18:10 +00:00
|
|
|
undefined,
|
2020-04-23 05:08:13 +00:00
|
|
|
(new Intl.DateTimeFormat()).resolvedOptions().fractionalSecondDigits);
|
|
|
|
|
|
|
|
assertEquals(
|
2020-07-09 22:18:10 +00:00
|
|
|
undefined,
|
2020-04-23 05:08:13 +00:00
|
|
|
(new Intl.DateTimeFormat("en", {fractionalSecondDigits: undefined}))
|
|
|
|
.resolvedOptions().fractionalSecondDigits);
|
|
|
|
|
2020-06-12 16:56:05 +00:00
|
|
|
// When timeStyle or dateStyle is present, we should throw TypeError
|
|
|
|
assertThrows(
|
|
|
|
() => (new Intl.DateTimeFormat(
|
|
|
|
"en", {timeStyle: "short", fractionalSecondDigits: 3})),
|
|
|
|
TypeError,
|
2020-09-10 00:21:00 +00:00
|
|
|
"Can't set option fractionalSecondDigits when timeStyle is used");
|
2020-06-12 16:56:05 +00:00
|
|
|
|
|
|
|
assertThrows(
|
|
|
|
() => (new Intl.DateTimeFormat(
|
|
|
|
"en", {dateStyle: "short", fractionalSecondDigits: 3})),
|
|
|
|
TypeError,
|
2020-09-10 00:21:00 +00:00
|
|
|
"Can't set option fractionalSecondDigits when dateStyle is used");
|