format.js (2011B)
1 // |reftest| skip-if(!this.hasOwnProperty("Intl")) 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 // Tests the format function with a diverse set of locales and options. 7 // Always use UTC to avoid dependencies on test environment. 8 9 var format; 10 var date = Date.UTC(2012, 11, 12, 3, 0, 0); 11 var longFormatOptions = {timeZone: "UTC", 12 year: "numeric", month: "long", day: "numeric", 13 hour: "numeric", minute: "numeric", second: "numeric"}; 14 15 // Locale en-US; default options. 16 format = new Intl.DateTimeFormat("en-us", {timeZone: "UTC"}); 17 assertEq(format.format(date), "12/12/2012"); 18 19 // Locale th-TH; default options. 20 // Thailand uses the Buddhist calendar. 21 format = new Intl.DateTimeFormat("th-th", {timeZone: "UTC"}); 22 assertEq(format.format(date), "12/12/2555"); 23 24 // Locale th-TH; long format, Thai digits. 25 format = new Intl.DateTimeFormat("th-th-u-nu-thai", longFormatOptions); 26 assertEq(format.format(date), "๑๒ ธันวาคม ๒๕๕๕ เวลา ๐๓:๐๐:๐๐"); 27 28 // Locale ja-JP; long format. 29 format = new Intl.DateTimeFormat("ja-jp", longFormatOptions); 30 assertEq(format.format(date), "2012年12月12日 3:00:00"); 31 32 // Locale ar-MA; long format, Islamic civilian calendar. 33 format = new Intl.DateTimeFormat("ar-ma-u-ca-islamicc", longFormatOptions); 34 assertEq(format.format(date), "28 محرم 1434 هـ في 03:00:00"); 35 36 // Locale en-IE: timeZoneName for crash test 37 format = new Intl.DateTimeFormat("en-IE", {timeZone: "UTC", timeZoneName: "short"}); 38 assertEq(format.format(date), "12/12/2012, UTC"); 39 40 // Test the .name property of the "format" getter. 41 var desc = Object.getOwnPropertyDescriptor(Intl.DateTimeFormat.prototype, "format"); 42 assertEq(desc !== undefined, true); 43 assertEq(typeof desc.get, "function"); 44 assertEq(desc.get.name, "get format"); 45 46 47 reportCompare(0, 0, 'ok');