summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/intl402/DateTimeFormat/prototype/format/fractionalSecondDigits.js
blob: 49218a3b39a8e4107abefc3505612e61bd78b7b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copyright 2019 Google Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-createdatetimeformat
description: Checks basic handling of fractionalSecondDigits.
features: [Intl.DateTimeFormat-fractionalSecondDigits]
locale: [en]
---*/

const d1 = new Date(2019, 7, 10,  1, 2, 3, 234);
const d2 = new Date(2019, 7, 10,  1, 2, 3, 567);

let dtf = new Intl.DateTimeFormat(
    'en', { minute: "numeric", second: "numeric", fractionalSecondDigits: undefined});
assert.sameValue(dtf.format(d1), "02:03", "no fractionalSecondDigits");
assert.sameValue(dtf.format(d2), "02:03", "no fractionalSecondDigits");

dtf = new Intl.DateTimeFormat(
    'en', { minute: "numeric", second: "numeric", fractionalSecondDigits: 1});
assert.sameValue(dtf.format(d1), "02:03.2", "1 fractionalSecondDigits round down");
assert.sameValue(dtf.format(d2), "02:03.5", "1 fractionalSecondDigits round down");

dtf = new Intl.DateTimeFormat(
    'en', { minute: "numeric", second: "numeric", fractionalSecondDigits: 2});
assert.sameValue(dtf.format(d1), "02:03.23", "2 fractionalSecondDigits round down");
assert.sameValue(dtf.format(d2), "02:03.56", "2 fractionalSecondDigits round down");

dtf = new Intl.DateTimeFormat(
    'en', { minute: "numeric", second: "numeric", fractionalSecondDigits: 3});
assert.sameValue(dtf.format(d1), "02:03.234", "3 fractionalSecondDigits round down");
assert.sameValue(dtf.format(d2), "02:03.567", "3 fractionalSecondDigits round down");

reportCompare(0, 0);