diff --git a/harness/dateConstants.js b/harness/dateConstants.js index 14213b8b52..f9e9fca081 100644 --- a/harness/dateConstants.js +++ b/harness/dateConstants.js @@ -13,3 +13,6 @@ var date_1999_end = 946684799999; var date_2000_start = 946684800000; var date_2099_end = 4102444799999; var date_2100_start = 4102444800000; + +var start_of_time = -8.64e15; +var end_of_time = 8.64e15; diff --git a/test/intl402/DateTimeFormat/prototype/format/date-constructor-not-called.js b/test/intl402/DateTimeFormat/prototype/format/date-constructor-not-called.js new file mode 100644 index 0000000000..1b0adf52cd --- /dev/null +++ b/test/intl402/DateTimeFormat/prototype/format/date-constructor-not-called.js @@ -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); +}); diff --git a/test/intl402/DateTimeFormat/prototype/format/time-clip-near-time-boundaries.js b/test/intl402/DateTimeFormat/prototype/format/time-clip-near-time-boundaries.js new file mode 100644 index 0000000000..b8af0eb5de --- /dev/null +++ b/test/intl402/DateTimeFormat/prototype/format/time-clip-near-time-boundaries.js @@ -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); +}); diff --git a/test/intl402/DateTimeFormat/prototype/format/time-clip-to-integer.js b/test/intl402/DateTimeFormat/prototype/format/time-clip-to-integer.js new file mode 100644 index 0000000000..243317606a --- /dev/null +++ b/test/intl402/DateTimeFormat/prototype/format/time-clip-to-integer.js @@ -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)"); diff --git a/test/intl402/DateTimeFormat/prototype/formatToParts/date-constructor-not-called.js b/test/intl402/DateTimeFormat/prototype/formatToParts/date-constructor-not-called.js new file mode 100644 index 0000000000..66234557f1 --- /dev/null +++ b/test/intl402/DateTimeFormat/prototype/formatToParts/date-constructor-not-called.js @@ -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); +}); diff --git a/test/intl402/DateTimeFormat/prototype/formatToParts/time-clip-near-time-boundaries.js b/test/intl402/DateTimeFormat/prototype/formatToParts/time-clip-near-time-boundaries.js new file mode 100644 index 0000000000..8501541781 --- /dev/null +++ b/test/intl402/DateTimeFormat/prototype/formatToParts/time-clip-near-time-boundaries.js @@ -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); +}); diff --git a/test/intl402/DateTimeFormat/prototype/formatToParts/time-clip-to-integer.js b/test/intl402/DateTimeFormat/prototype/formatToParts/time-clip-to-integer.js new file mode 100644 index 0000000000..0b95ef68e2 --- /dev/null +++ b/test/intl402/DateTimeFormat/prototype/formatToParts/time-clip-to-integer.js @@ -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)");