Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / intl / l10n / test / test_datetimeformat.js
blob4c0794424bb03ddfb510b2aa384e3713abd8a02b
1 /* Any copyright is dedicated to the Public Domain.
2    http://creativecommons.org/publicdomain/zero/1.0/ */
4 const FIREFOX_RELEASE_TIMESTAMP = 1032800850000;
5 const FIREFOX_RELEASE_DATE = new Date(FIREFOX_RELEASE_TIMESTAMP);
7 add_task(function test_date_time_format() {
8   const bundle = new FluentBundle(["en-US"]);
10   bundle.addResource(
11     new FluentResource(`
12 dt-arg = Just the arg is: {$dateArg}
13 dt-bare = The bare date is: { DATETIME($dateArg) }
14 dt-month-year = Months and year are not time-zone dependent here: { DATETIME($dateArg, month: "long") }
15 dt-bad = This is a bad month: { DATETIME($dateArg, month: "oops") }
16 # TODO - Bug 1707728:
17 dt-timezone = The timezone: { DATETIME($dateArg, timezone: "America/New_York") }
18 dt-unknown = Unknown: { DATETIME($dateArg, unknown: "unknown") }
19 dt-style = Style formatting: { DATETIME($dateArg, dateStyle: "short", timeStyle: "short") }
20     `)
21   );
23   function testMessage(id, dateArg, expectedMessage) {
24     const message = bundle.formatPattern(bundle.getMessage(id).value, {
25       dateArg,
26     });
28     if (typeof expectedMessage === "object") {
29       // Assume regex.
30       ok(
31         expectedMessage.test(message),
32         `"${message}" matches regex: ${expectedMessage.toString()}`
33       );
34     } else {
35       // Assume string.
36       equal(message, expectedMessage);
37     }
38   }
40   // TODO - Bug 1707728 - Some of these are implemented as regexes since time zones are not
41   // supported in fluent messages as of yet. They could be simplified if a time zone were
42   // specified.
43   testMessage(
44     "dt-arg",
45     FIREFOX_RELEASE_DATE,
46     /^Just the arg is: (Sun|Mon|Tue) Sep \d+ 2002 \d+:\d+:\d+ .* \(.*\)$/
47   );
48   testMessage(
49     "dt-bare",
50     FIREFOX_RELEASE_TIMESTAMP,
51     /^The bare date is: Sep \d+, 2002, \d+:\d+:\d+ (AM|PM)$/
52   );
53   testMessage(
54     "dt-month-year",
55     FIREFOX_RELEASE_TIMESTAMP,
56     "Months and year are not time-zone dependent here: September"
57   );
58   testMessage(
59     "dt-bad",
60     FIREFOX_RELEASE_TIMESTAMP,
61     /^This is a bad month: Sep \d+, 2002, \d+:\d+:\d+ (AM|PM)$/
62   );
63   testMessage(
64     "dt-unknown",
65     FIREFOX_RELEASE_TIMESTAMP,
66     /^Unknown: Sep \d+, 2002, \d+:\d+:\d+ (AM|PM)$/
67   );
68   testMessage(
69     "dt-style",
70     FIREFOX_RELEASE_TIMESTAMP,
71     /^Style formatting: \d+\/\d+\/\d+, \d+:\d+ (AM|PM)$/
72   );
74 // TODO - Bug 1707728
75 // testMessage("dt-timezone", ...);
76 });