michael@0: // |reftest| skip-if(!this.hasOwnProperty("Intl")) michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: // Tests the format function with a diverse set of locales and options. michael@0: // Always use UTC to avoid dependencies on test environment. michael@0: michael@0: var format; michael@0: var date = Date.UTC(2012, 11, 12, 3, 0, 0); michael@0: var longFormatOptions = {timeZone: "UTC", michael@0: year: "numeric", month: "long", day: "numeric", michael@0: hour: "numeric", minute: "numeric", second: "numeric"}; michael@0: michael@0: // Locale en-US; default options. michael@0: format = new Intl.DateTimeFormat("en-us", {timeZone: "UTC"}); michael@0: assertEq(format.format(date), "12/12/2012"); michael@0: michael@0: // Locale th-TH; default options. michael@0: // Thailand uses the Buddhist calendar. michael@0: format = new Intl.DateTimeFormat("th-th", {timeZone: "UTC"}); michael@0: assertEq(format.format(date), "12/12/2555"); michael@0: michael@0: // Locale th-TH; long format, Thai digits. michael@0: format = new Intl.DateTimeFormat("th-th-u-nu-thai", longFormatOptions); michael@0: assertEq(format.format(date), "๑๒ ธันวาคม ๒๕๕๕ ๐๓:๐๐:๐๐"); michael@0: michael@0: // Locale ja-JP; long format. michael@0: format = new Intl.DateTimeFormat("ja-jp", longFormatOptions); michael@0: assertEq(format.format(date), "2012年12月12日 3:00:00"); michael@0: michael@0: // Locale ar-MA; long format, Islamic civilian calendar. michael@0: format = new Intl.DateTimeFormat("ar-ma-u-ca-islamicc", longFormatOptions); michael@0: assertEq(format.format(date), "28 محرم، 1434 3:00:00 ص"); michael@0: michael@0: reportCompare(0, 0, 'ok');