summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/intl402/DateTimeFormat/prototype/formatRangeToParts/argument-near-time-boundaries.js
blob: ea87893bf1262f327a893e9532fd9837768ed3f1 (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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright (C) 2017 André Bargull. All rights reserved.
// Copyright (C) 2019 Igalia S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-partitiondatetimerangepattern
description: >
  TimeClip is applied when calling Intl.DateTimeFormat.prototype.formatRangeToParts.
info: |
  PartitionDateTimeRangePattern ( dateTimeFormat, x, y )

  1. Let x be TimeClip(x).
  2. If x is NaN, throw a RangeError exception.
  3. Let y be TimeClip(y).
  4. If y is NaN, throw a RangeError exception.

  TimeClip ( time )
  ...
  2. If abs(time) > 8.64 × 10^15, return NaN.
  ...

includes: [dateConstants.js]
features: [Intl.DateTimeFormat-formatRange]
---*/

const dtf = new Intl.DateTimeFormat();
const date = Date.now();

// Test values near the start of the ECMAScript time range.
assert.throws(RangeError, function() {
  dtf.formatRangeToParts(start_of_time - 1, date);
});
assert.throws(RangeError, function() {
  dtf.formatRangeToParts(date, start_of_time - 1);
});
assert.sameValue(typeof dtf.formatRangeToParts(start_of_time, date), "object");
assert.sameValue(typeof dtf.formatRangeToParts(start_of_time + 1, date), "object");

// Test values near the end of the ECMAScript time range.
assert.sameValue(typeof dtf.formatRangeToParts(date, end_of_time - 1), "object");
assert.sameValue(typeof dtf.formatRangeToParts(date, end_of_time), "object");
assert.throws(RangeError, function() {
  dtf.formatRangeToParts(end_of_time + 1, date);
});
assert.throws(RangeError, function() {
  dtf.formatRangeToParts(date, end_of_time + 1);
});

reportCompare(0, 0);