mirror of
https://github.com/tc39/test262.git
synced 2025-04-08 19:35:28 +02:00
Add test cases for tc39/ecma402#194
This commit is contained in:
parent
7c5b5bf750
commit
40a7bd2401
@ -13,3 +13,6 @@ var date_1999_end = 946684799999;
|
|||||||
var date_2000_start = 946684800000;
|
var date_2000_start = 946684800000;
|
||||||
var date_2099_end = 4102444799999;
|
var date_2099_end = 4102444799999;
|
||||||
var date_2100_start = 4102444800000;
|
var date_2100_start = 4102444800000;
|
||||||
|
|
||||||
|
var start_of_time = -8.64e15;
|
||||||
|
var end_of_time = 8.64e15;
|
||||||
|
36
test/intl402/DateTimeFormat/prototype/format/date-constructor-not-called.js
vendored
Normal file
36
test/intl402/DateTimeFormat/prototype/format/date-constructor-not-called.js
vendored
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
// Copyright (C) 2017 André Bargull. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-partitiondatetimepattern
|
||||||
|
description: |
|
||||||
|
The Date constructor is not called to convert the input value.
|
||||||
|
info: >
|
||||||
|
12.1.5 DateTime Format Functions
|
||||||
|
|
||||||
|
...
|
||||||
|
3. If date is not provided or is undefined, then
|
||||||
|
...
|
||||||
|
4. Else,
|
||||||
|
a. Let x be ? ToNumber(date).
|
||||||
|
5. Return FormatDateTime(dtf, x).
|
||||||
|
|
||||||
|
12.1.6 PartitionDateTimePattern ( dateTimeFormat, x )
|
||||||
|
|
||||||
|
1. Let x be TimeClip(x).
|
||||||
|
2. If x is NaN, throw a RangeError exception.
|
||||||
|
3. ...
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var dtf = new Intl.DateTimeFormat();
|
||||||
|
|
||||||
|
var dateTimeString = "2017-11-10T14:09:00.000Z";
|
||||||
|
|
||||||
|
// |dateTimeString| is valid ISO-8601 style date/time string.
|
||||||
|
assert.notSameValue(new Date(dateTimeString), NaN);
|
||||||
|
|
||||||
|
// Ensure string input values are not converted to time values by calling the
|
||||||
|
// Date constructor.
|
||||||
|
assert.throws(RangeError, function() {
|
||||||
|
dtf.format(dateTimeString);
|
||||||
|
});
|
37
test/intl402/DateTimeFormat/prototype/format/time-clip-near-time-boundaries.js
vendored
Normal file
37
test/intl402/DateTimeFormat/prototype/format/time-clip-near-time-boundaries.js
vendored
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
// Copyright (C) 2017 André Bargull. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-partitiondatetimepattern
|
||||||
|
description: |
|
||||||
|
TimeClip is applied when calling Intl.DateTimeFormat.prototype.format.
|
||||||
|
info: >
|
||||||
|
12.1.6 PartitionDateTimePattern ( dateTimeFormat, x )
|
||||||
|
|
||||||
|
1. Let x be TimeClip(x).
|
||||||
|
2. If x is NaN, throw a RangeError exception.
|
||||||
|
3. ...
|
||||||
|
|
||||||
|
20.3.1.15 TimeClip ( time )
|
||||||
|
...
|
||||||
|
2. If abs(time) > 8.64 × 10^15, return NaN.
|
||||||
|
...
|
||||||
|
|
||||||
|
includes: [dateConstants.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var dtf = new Intl.DateTimeFormat();
|
||||||
|
|
||||||
|
// Test values near the start of the ECMAScript time range.
|
||||||
|
assert.throws(RangeError, function() {
|
||||||
|
dtf.format(start_of_time - 1);
|
||||||
|
});
|
||||||
|
assert.sameValue(typeof dtf.format(start_of_time), "string");
|
||||||
|
assert.sameValue(typeof dtf.format(start_of_time + 1), "string");
|
||||||
|
|
||||||
|
// Test values near the end of the ECMAScript time range.
|
||||||
|
assert.sameValue(typeof dtf.format(end_of_time - 1), "string");
|
||||||
|
assert.sameValue(typeof dtf.format(end_of_time), "string");
|
||||||
|
assert.throws(RangeError, function() {
|
||||||
|
dtf.format(end_of_time + 1);
|
||||||
|
});
|
37
test/intl402/DateTimeFormat/prototype/format/time-clip-to-integer.js
vendored
Normal file
37
test/intl402/DateTimeFormat/prototype/format/time-clip-to-integer.js
vendored
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
// Copyright (C) 2017 André Bargull. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-partitiondatetimepattern
|
||||||
|
description: |
|
||||||
|
TimeClip applies ToInteger on its input value.
|
||||||
|
info: >
|
||||||
|
12.1.6 PartitionDateTimePattern ( dateTimeFormat, x )
|
||||||
|
|
||||||
|
1. Let x be TimeClip(x).
|
||||||
|
2. ...
|
||||||
|
|
||||||
|
20.3.1.15 TimeClip ( time )
|
||||||
|
...
|
||||||
|
3. Let clippedTime be ! ToInteger(time).
|
||||||
|
4. If clippedTime is -0, set clippedTime to +0.
|
||||||
|
5. Return clippedTime.
|
||||||
|
---*/
|
||||||
|
|
||||||
|
// Switch to a time format instead of using DateTimeFormat's default date-only format.
|
||||||
|
var dtf = new Intl.DateTimeFormat(undefined, {
|
||||||
|
hour: "numeric", minute: "numeric", second: "numeric"
|
||||||
|
});
|
||||||
|
|
||||||
|
var expected = dtf.format(0);
|
||||||
|
|
||||||
|
assert.sameValue(dtf.format(-0.9), expected, "format(-0.9)");
|
||||||
|
assert.sameValue(dtf.format(-0.5), expected, "format(-0.5)");
|
||||||
|
assert.sameValue(dtf.format(-0.1), expected, "format(-0.1)");
|
||||||
|
assert.sameValue(dtf.format(-Number.MIN_VALUE), expected, "format(-Number.MIN_VALUE)");
|
||||||
|
assert.sameValue(dtf.format(-0), expected, "format(-0)");
|
||||||
|
assert.sameValue(dtf.format(+0), expected, "format(+0)");
|
||||||
|
assert.sameValue(dtf.format(Number.MIN_VALUE), expected, "format(Number.MIN_VALUE)");
|
||||||
|
assert.sameValue(dtf.format(0.1), expected, "format(0.1)");
|
||||||
|
assert.sameValue(dtf.format(0.5), expected, "format(0.5)");
|
||||||
|
assert.sameValue(dtf.format(0.9), expected, "format(0.9)");
|
36
test/intl402/DateTimeFormat/prototype/formatToParts/date-constructor-not-called.js
vendored
Normal file
36
test/intl402/DateTimeFormat/prototype/formatToParts/date-constructor-not-called.js
vendored
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
// Copyright (C) 2017 André Bargull. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-partitiondatetimepattern
|
||||||
|
description: |
|
||||||
|
The Date constructor is not called to convert the input value.
|
||||||
|
info: >
|
||||||
|
12.4.4 Intl.DateTimeFormat.prototype.formatToParts ( date )
|
||||||
|
|
||||||
|
...
|
||||||
|
4. If date is undefined, then
|
||||||
|
...
|
||||||
|
5. Else,
|
||||||
|
a. Let x be ? ToNumber(date).
|
||||||
|
5. Return ? FormatDateTimeToParts(dtf, x).
|
||||||
|
|
||||||
|
12.1.6 PartitionDateTimePattern ( dateTimeFormat, x )
|
||||||
|
|
||||||
|
1. Let x be TimeClip(x).
|
||||||
|
2. If x is NaN, throw a RangeError exception.
|
||||||
|
3. ...
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var dtf = new Intl.DateTimeFormat();
|
||||||
|
|
||||||
|
var dateTimeString = "2017-11-10T14:09:00.000Z";
|
||||||
|
|
||||||
|
// |dateTimeString| is valid ISO-8601 style date/time string.
|
||||||
|
assert.notSameValue(new Date(dateTimeString), NaN);
|
||||||
|
|
||||||
|
// Ensure string input values are not converted to time values by calling the
|
||||||
|
// Date constructor.
|
||||||
|
assert.throws(RangeError, function() {
|
||||||
|
dtf.formatToParts(dateTimeString);
|
||||||
|
});
|
37
test/intl402/DateTimeFormat/prototype/formatToParts/time-clip-near-time-boundaries.js
vendored
Normal file
37
test/intl402/DateTimeFormat/prototype/formatToParts/time-clip-near-time-boundaries.js
vendored
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
// Copyright (C) 2017 André Bargull. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-partitiondatetimepattern
|
||||||
|
description: |
|
||||||
|
TimeClip is applied when calling Intl.DateTimeFormat.prototype.formatToParts.
|
||||||
|
info: >
|
||||||
|
12.1.6 PartitionDateTimePattern ( dateTimeFormat, x )
|
||||||
|
|
||||||
|
1. Let x be TimeClip(x).
|
||||||
|
2. If x is NaN, throw a RangeError exception.
|
||||||
|
3. ...
|
||||||
|
|
||||||
|
20.3.1.15 TimeClip ( time )
|
||||||
|
...
|
||||||
|
2. If abs(time) > 8.64 × 10^15, return NaN.
|
||||||
|
...
|
||||||
|
|
||||||
|
includes: [dateConstants.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var dtf = new Intl.DateTimeFormat();
|
||||||
|
|
||||||
|
// Test values near the start of the ECMAScript time range.
|
||||||
|
assert.throws(RangeError, function() {
|
||||||
|
dtf.formatToParts(start_of_time - 1);
|
||||||
|
});
|
||||||
|
assert.sameValue(typeof dtf.formatToParts(start_of_time), "object");
|
||||||
|
assert.sameValue(typeof dtf.formatToParts(start_of_time + 1), "object");
|
||||||
|
|
||||||
|
// Test values near the end of the ECMAScript time range.
|
||||||
|
assert.sameValue(typeof dtf.formatToParts(end_of_time - 1), "object");
|
||||||
|
assert.sameValue(typeof dtf.formatToParts(end_of_time), "object");
|
||||||
|
assert.throws(RangeError, function() {
|
||||||
|
dtf.formatToParts(end_of_time + 1);
|
||||||
|
});
|
41
test/intl402/DateTimeFormat/prototype/formatToParts/time-clip-to-integer.js
vendored
Normal file
41
test/intl402/DateTimeFormat/prototype/formatToParts/time-clip-to-integer.js
vendored
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
// Copyright (C) 2017 André Bargull. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-partitiondatetimepattern
|
||||||
|
description: |
|
||||||
|
TimeClip applies ToInteger on its input value.
|
||||||
|
info: >
|
||||||
|
12.1.6 PartitionDateTimePattern ( dateTimeFormat, x )
|
||||||
|
|
||||||
|
1. Let x be TimeClip(x).
|
||||||
|
2. ...
|
||||||
|
|
||||||
|
20.3.1.15 TimeClip ( time )
|
||||||
|
...
|
||||||
|
3. Let clippedTime be ! ToInteger(time).
|
||||||
|
4. If clippedTime is -0, set clippedTime to +0.
|
||||||
|
5. Return clippedTime.
|
||||||
|
---*/
|
||||||
|
|
||||||
|
// Switch to a time format instead of using DateTimeFormat's default date-only format.
|
||||||
|
var dtf = new Intl.DateTimeFormat(undefined, {
|
||||||
|
hour: "numeric", minute: "numeric", second: "numeric"
|
||||||
|
});
|
||||||
|
|
||||||
|
function formatAsString(dtf, time) {
|
||||||
|
return dtf.formatToParts(time).map(part => part.value).join("");
|
||||||
|
}
|
||||||
|
|
||||||
|
var expected = formatAsString(dtf, 0);
|
||||||
|
|
||||||
|
assert.sameValue(formatAsString(dtf, -0.9), expected, "formatToParts(-0.9)");
|
||||||
|
assert.sameValue(formatAsString(dtf, -0.5), expected, "formatToParts(-0.5)");
|
||||||
|
assert.sameValue(formatAsString(dtf, -0.1), expected, "formatToParts(-0.1)");
|
||||||
|
assert.sameValue(formatAsString(dtf, -Number.MIN_VALUE), expected, "formatToParts(-Number.MIN_VALUE)");
|
||||||
|
assert.sameValue(formatAsString(dtf, -0), expected, "formatToParts(-0)");
|
||||||
|
assert.sameValue(formatAsString(dtf, +0), expected, "formatToParts(+0)");
|
||||||
|
assert.sameValue(formatAsString(dtf, Number.MIN_VALUE), expected, "formatToParts(Number.MIN_VALUE)");
|
||||||
|
assert.sameValue(formatAsString(dtf, 0.1), expected, "formatToParts(0.1)");
|
||||||
|
assert.sameValue(formatAsString(dtf, 0.5), expected, "formatToParts(0.5)");
|
||||||
|
assert.sameValue(formatAsString(dtf, 0.9), expected, "formatToParts(0.9)");
|
Loading…
x
Reference in New Issue
Block a user