js/src/tests/test262/intl402/ch13/13.3/13.3.0_7.js

Wed, 31 Dec 2014 13:27:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 13:27:57 +0100
branch
TOR_BUG_3246
changeset 6
8bccb770b82d
permissions
-rw-r--r--

Ignore runtime configuration files generated during quality assurance.

michael@0 1 // Copyright 2012 Mozilla Corporation. All rights reserved.
michael@0 2 // This code is governed by the BSD license found in the LICENSE file.
michael@0 3
michael@0 4 /**
michael@0 5 * @description Tests that Date.prototype.toLocaleString & Co. produces the same results as Intl.DateTimeFormat.
michael@0 6 * @author Norbert Lindenberg
michael@0 7 */
michael@0 8
michael@0 9 $INCLUDE("testIntl.js");
michael@0 10
michael@0 11 var functions = {
michael@0 12 toLocaleString: [Date.prototype.toLocaleString,
michael@0 13 {year: "numeric", month: "numeric", day: "numeric", hour: "numeric", minute: "numeric", second: "numeric"}],
michael@0 14 toLocaleDateString: [Date.prototype.toLocaleDateString,
michael@0 15 {year: "numeric", month: "numeric", day: "numeric"}],
michael@0 16 toLocaleTimeString: [Date.prototype.toLocaleTimeString,
michael@0 17 {hour: "numeric", minute: "numeric", second: "numeric"}]
michael@0 18 };
michael@0 19 var dates = [new Date(), new Date(0), new Date(Date.parse("1989-11-09T17:57:00Z"))];
michael@0 20 var locales = [undefined, ["de"], ["th-u-ca-gregory-nu-thai"], ["en"], ["ja-u-ca-japanese"], ["ar-u-ca-islamicc-nu-arab"]];
michael@0 21 var options = [
michael@0 22 undefined,
michael@0 23 {hour12: false},
michael@0 24 {month: "long", day: "numeric", hour: "2-digit", minute: "2-digit"}
michael@0 25 ];
michael@0 26
michael@0 27 Object.getOwnPropertyNames(functions).forEach(function (p) {
michael@0 28 var f = functions[p][0];
michael@0 29 var defaults = functions[p][1];
michael@0 30 locales.forEach(function (locales) {
michael@0 31 options.forEach(function (options) {
michael@0 32 var constructorOptions = options;
michael@0 33 if (options === undefined) {
michael@0 34 constructorOptions = defaults;
michael@0 35 } else if (options.day === undefined) {
michael@0 36 // for simplicity, our options above have either both date and time or neither
michael@0 37 constructorOptions = Object.create(defaults);
michael@0 38 for (var prop in options) {
michael@0 39 if (options.hasOwnProperty(prop)) {
michael@0 40 constructorOptions[prop] = options[prop];
michael@0 41 }
michael@0 42 }
michael@0 43 }
michael@0 44 var referenceDateTimeFormat = new Intl.DateTimeFormat(locales, constructorOptions);
michael@0 45 var referenceFormatted = dates.map(referenceDateTimeFormat.format);
michael@0 46
michael@0 47 var formatted = dates.map(function (a) { return f.call(a, locales, options); });
michael@0 48 try {
michael@0 49 testArraysAreSame(referenceFormatted, formatted);
michael@0 50 } catch (e) {
michael@0 51 e.message += " (Testing with locales " + locales + "; options " +
michael@0 52 (options ? JSON.stringify(options) : options) + ".)";
michael@0 53 throw e;
michael@0 54 }
michael@0 55 });
michael@0 56 });
michael@0 57 });
michael@0 58

mercurial