js/src/tests/Intl/DateTimeFormat/format.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/Intl/DateTimeFormat/format.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,36 @@
     1.4 +// |reftest| skip-if(!this.hasOwnProperty("Intl"))
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +// Tests the format function with a diverse set of locales and options.
    1.10 +// Always use UTC to avoid dependencies on test environment.
    1.11 +
    1.12 +var format;
    1.13 +var date = Date.UTC(2012, 11, 12, 3, 0, 0);
    1.14 +var longFormatOptions = {timeZone: "UTC",
    1.15 +                         year: "numeric", month: "long", day: "numeric",
    1.16 +                         hour: "numeric", minute: "numeric", second: "numeric"};
    1.17 +
    1.18 +// Locale en-US; default options.
    1.19 +format = new Intl.DateTimeFormat("en-us", {timeZone: "UTC"});
    1.20 +assertEq(format.format(date), "12/12/2012");
    1.21 +
    1.22 +// Locale th-TH; default options.
    1.23 +// Thailand uses the Buddhist calendar.
    1.24 +format = new Intl.DateTimeFormat("th-th", {timeZone: "UTC"});
    1.25 +assertEq(format.format(date), "12/12/2555");
    1.26 +
    1.27 +// Locale th-TH; long format, Thai digits.
    1.28 +format = new Intl.DateTimeFormat("th-th-u-nu-thai", longFormatOptions);
    1.29 +assertEq(format.format(date), "๑๒ ธันวาคม ๒๕๕๕ ๐๓:๐๐:๐๐");
    1.30 +
    1.31 +// Locale ja-JP; long format.
    1.32 +format = new Intl.DateTimeFormat("ja-jp", longFormatOptions);
    1.33 +assertEq(format.format(date), "2012年12月12日 3:00:00");
    1.34 +
    1.35 +// Locale ar-MA; long format, Islamic civilian calendar.
    1.36 +format = new Intl.DateTimeFormat("ar-ma-u-ca-islamicc", longFormatOptions);
    1.37 +assertEq(format.format(date), "28 محرم، 1434 3:00:00 ص");
    1.38 +
    1.39 +reportCompare(0, 0, 'ok');

mercurial