瀏覽代碼

Passing basic DateTimeFormat tests

Jack Horton 8 年之前
父節點
當前提交
bee273d43f

+ 9 - 0
lib/Runtime/Library/InJavascript/Intl.js

@@ -1414,6 +1414,10 @@
                     "2-digit": "hha",
                     numeric: "ha",
                 },
+                hour24: {
+                    "2-digit": "HHa",
+                    numeric: "Ha",
+                },
                 minute: {
                     "2-digit": "mm",
                     numeric: "m",
@@ -1632,6 +1636,8 @@
                 return _.reduce(_.keys(resolved), function (skeleton, key) {
                     if (key === "hour" && options.hour12 === true) {
                         skeleton += skeletonSymbolForOption["hour12"][resolved[key]];
+                    } else if (key === "hour" && options.hour12 === false) {
+                        skeleton += skeletonSymbolForOption["hour24"][resolved[key]];
                     } else {
                         skeleton += skeletonSymbolForOption[key][resolved[key]];
                     }
@@ -1694,6 +1700,9 @@
                     }
                 });
 
+                // get the formatMatcher for validation only
+                GetOption(options, "formatMatcher", "string", ["basic", "best fit"], "best fit");
+
                 // SPEC CODE
                 // const localeWithoutSubtagsData = localeData[localeWithoutSubtags];
                 // const formats = localeWithoutSubtagsData.formats;

+ 52 - 0
test/Intl/DateTimeFormat.js

@@ -0,0 +1,52 @@
+//-------------------------------------------------------------------------------------------------------
+// Copyright (C) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
+//-------------------------------------------------------------------------------------------------------
+
+WScript.LoadScriptFile("..\\UnitTestFramework\\UnitTestFramework.js");
+
+var tests = [
+    {
+        name: "Basic tests",
+        body: function () {
+            const date = new Date(2000, 1, 1, 1, 1, 1);
+            function equal(options, expected, message) {
+                const result = new Intl.DateTimeFormat("en-US", options).format(date);
+                result.replace("\u200e", ""); // replace bi-di markers
+                assert.areEqual(expected, result, message);
+            }
+
+            function matches(options, expected, message) {
+                const result = new Intl.DateTimeFormat("en-US", options).format(date);
+                result.replace("\u200e", ""); // replace bi-di markers
+                assert.matches(expected, result, message);
+            }
+
+            equal({ year: "numeric" }, "2000", "Formatting year as numeric");
+            equal({ year: "2-digit" }, "00", "Formatting year as 2-digit.");
+
+            equal({ month: "numeric" }, "2", "Formatting month as numeric.");
+            equal({ month: "2-digit" }, "02", "Formatting month as 2-digit.");
+            equal({ month: "long" }, "February", "Formatting month as 2-digit.");
+            equal({ month: "short" }, "Feb", "Formatting month as numeric.");
+            matches({ month: "narrow" }, /F(eb)?/, "Formatting month as narrow."); // WinGlob narrow is Feb, ICU narrow is F
+
+            equal({ day: "2-digit" }, "01", "Formatting day as 2-digit.");
+            equal({ day: "numeric" }, "1", "Formatting day as numeric.");
+
+            matches({ hour: "2-digit" }, /0?1 AM/, "Formatting hour as 2-digit."); // ICU 2-digit hour skeleton (jj) doesn't transform into hh/HH correctly in en-US
+            equal({ hour: "numeric" }, "1 AM", "Formatting hour as numeric.");
+
+            equal({ hour: "numeric", minute: "2-digit" }, "1:01 AM", "Formatting hour as numeric and minute as 2-digit.");
+            equal({ hour: "numeric", minute: "numeric" }, "1:01 AM", "Formatting hour as numeric and minute as numeric.");
+
+            equal({ hour: "numeric", minute: "2-digit", second: "2-digit" }, "1:01:01 AM", "Formatting hour as numeric, minute as 2-digit and second as 2-digit.");
+            matches({ hour: "numeric", minute: "2-digit", second: "numeric" }, /1:01:0?1 AM/, "Formatting hour as numeric, minute as 2-digit and second as numeric."); // WinGlob doesn't have non-2-digit seconds
+
+            equal({ hour: "numeric", hour12: true }, "1 AM", "Formatting hour as numeric with hour12=true.");
+            matches({ hour: "numeric", hour12: false }, /(1:00|01)/, "Formatting hour as numeric with hour12=false.");
+        }
+    }
+];
+
+testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" });

+ 1 - 1
test/Intl/DateTimeFormatInvalidOptions.js

@@ -23,7 +23,7 @@ var tests = [
                 }
                 catch (e) {
                     if (!(e instanceof RangeError)) {
-                        assert.fail("Incorrect exception was thrown.");
+                        assert.fail(`Incorrect exception was thrown: ${e.message}`);
                     }
                     assert.isTrue(e.message.indexOf(validValues) !== -1,
                         "Checking exception message for correct values string. Looking for: " + validValues +

+ 0 - 40
test/Intl/DateTimeFormatOptions.js

@@ -1,40 +0,0 @@
-//-------------------------------------------------------------------------------------------------------
-// Copyright (C) Microsoft. All rights reserved.
-// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
-//-------------------------------------------------------------------------------------------------------
-
-WScript.LoadScriptFile("..\\UnitTestFramework\\UnitTestFramework.js");
-
-// NOTE: \u200e is the U+200E LEFT-TO-RIGHT MARK
-var tests = [
-    {
-        name: "Test Valid Options",
-        body: function () {
-            assert.areEqual(new Intl.DateTimeFormat("en-US", { year: "numeric" }).format(new Date(2000, 1, 1, 1, 1, 1)), "\u200e2000", "Formatting year as numeric.");
-            assert.areEqual(new Intl.DateTimeFormat("en-US", { year: "2-digit" }).format(new Date(2000, 1, 1, 1, 1, 1)), "\u200e00", "Formatting year as 2-digit.");
-
-            assert.areEqual(new Intl.DateTimeFormat("en-US", { month: "numeric" }).format(new Date(2000, 1, 1, 1, 1, 1)), "\u200e2", "Formatting month as numeric.");
-            assert.areEqual(new Intl.DateTimeFormat("en-US", { month: "2-digit" }).format(new Date(2000, 1, 1, 1, 1, 1)), "\u200e02", "Formatting month as 2-digit.");
-            assert.areEqual(new Intl.DateTimeFormat("en-US", { month: "long" }).format(new Date(2000, 1, 1, 1, 1, 1)), "\u200eFebruary", "Formatting month as 2-digit.");
-            assert.areEqual(new Intl.DateTimeFormat("en-US", { month: "short" }).format(new Date(2000, 1, 1, 1, 1, 1)), "\u200eFeb", "Formatting month as numeric.");
-            assert.areEqual(new Intl.DateTimeFormat("en-US", { month: "narrow" }).format(new Date(2000, 1, 1, 1, 1, 1)), "\u200eFeb", "Formatting month as narrow.");
-
-            assert.areEqual(new Intl.DateTimeFormat("en-US", { day: "2-digit" }).format(new Date(2000, 1, 1, 1, 1, 1)), "\u200e01", "Formatting day as 2-digit.");
-            assert.areEqual(new Intl.DateTimeFormat("en-US", { day: "numeric" }).format(new Date(2000, 1, 1, 1, 1, 1)), "\u200e1", "Formatting day as numeric.");
-
-            assert.areEqual(new Intl.DateTimeFormat("en-US", { hour: "2-digit" }).format(new Date(2000, 1, 1, 1, 1, 1)), "\u200e01\u200e \u200eAM", "Formatting hour as 2-digit.");
-            assert.areEqual(new Intl.DateTimeFormat("en-US", { hour: "numeric" }).format(new Date(2000, 1, 1, 1, 1, 1)), "\u200e1\u200e \u200eAM", "Formatting hour as numeric.");
-
-            assert.areEqual(new Intl.DateTimeFormat("en-US", { hour: "2-digit", minute: "2-digit" }).format(new Date(2000, 1, 1, 1, 1, 1)), "\u200e01\u200e:\u200e01\u200e \u200eAM", "Formatting hour as 2-digit and minute as 2-digit.");
-            assert.areEqual(new Intl.DateTimeFormat("en-US", { hour: "2-digit", minute: "numeric" }).format(new Date(2000, 1, 1, 1, 1, 1)), "\u200e01\u200e:\u200e01\u200e \u200eAM", "Formatting hour as 2-digit and minute as numeric.");
-
-            assert.areEqual(new Intl.DateTimeFormat("en-US", { hour: "2-digit", minute: "2-digit", second: "2-digit" }).format(new Date(2000, 1, 1, 1, 1, 1)), "\u200e01\u200e:\u200e01\u200e:\u200e01\u200e \u200eAM", "Formatting hour as 2-digit, minute as 2-digit and second as 2-digit.");
-            assert.areEqual(new Intl.DateTimeFormat("en-US", { hour: "2-digit", minute: "2-digit", second: "numeric" }).format(new Date(2000, 1, 1, 1, 1, 1)), "\u200e01\u200e:\u200e01\u200e:\u200e01\u200e \u200eAM", "Formatting hour as 2-digit, minute as 2-digit and second as numeric.");
-
-            assert.areEqual(new Intl.DateTimeFormat("en-US", { hour: "numeric", hour12: true }).format(new Date(2000, 1, 1, 1, 1, 1)), "\u200e1\u200e \u200eAM", "Formatting hour as numeric with hour12=true.");
-            assert.areEqual(new Intl.DateTimeFormat("en-US", { hour: "numeric", hour12: false }).format(new Date(2000, 1, 1, 1, 1, 1)), "\u200e1\u200e:\u200e00", "Formatting hour as numeric with hour12=false.");
-        }
-    }
-];
-
-testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" });

+ 6 - 6
test/Intl/rlexe.xml

@@ -11,28 +11,28 @@
   <test>
     <default>
       <files>Collator.js</files>
-      <tags>Intl,require_winglob</tags>
+      <tags>Intl</tags>
     </default>
   </test>
   <test>
     <default>
       <files>CollatorOptions.js</files>
       <compile-flags>-args summary -endargs</compile-flags>
-      <tags>Intl,require_winglob</tags>
+      <tags>Intl</tags>
     </default>
   </test>
   <test>
     <default>
       <files>DateTimeFormatInvalidOptions.js</files>
       <compile-flags>-args summary -endargs</compile-flags>
-      <tags>Intl</tags>
+      <tags>Intl,require_winglob</tags>
     </default>
   </test>
   <test>
     <default>
-      <files>DateTimeFormatOptions.js</files>
+      <files>DateTimeFormat.js</files>
       <compile-flags>-args summary -endargs</compile-flags>
-      <tags>Intl,require_winglob</tags>
+      <tags>Intl,</tags>
     </default>
   </test>
   <test>
@@ -61,7 +61,7 @@
     <default>
       <files>SupportedLocalesOf.js</files>
       <compile-flags>-args summary -endargs</compile-flags>
-      <tags>Intl,require_winglob</tags>
+      <tags>Intl</tags>
     </default>
   </test>
   <test>