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.

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

mercurial