Explorar el Código

Military time zone calculation is wrong

According to source [1] and [2], the calculation of military
time zone is wrong in ChakraCore. It should be the opposite:
a corresponds to UTC+1, b corresponds to UTC+2, ... e.g.
Eastern standard time is R, or UTC-5.

From [2]:

The suffix indicates the correction (for description, see table) which must be applied to the time as expressed in order to convert to GMT.

Test cases are included.

[1] https://www.timeanddate.com/time/zones/military
[2] https://web.archive.org/web/20160304061301/http://jcs.dtic.mil/j6/cceb/acps/acp121/ACP121I.pdf, pp. 51-52
Xiaoyin Liu hace 8 años
padre
commit
f9bf2724a7

+ 4 - 4
lib/Runtime/Library/DateImplementation.cpp

@@ -1159,8 +1159,8 @@ Error:
                     // military version of time zone
                     // z = GMT
                     // j isn't used
-                    // a to m are -1 to -12
-                    // n to y are 1 to 12
+                    // a to m are 1 to 12
+                    // n to y are -1 to -12
                     if (lwNil != lwZone)
                     {
                         goto LError;
@@ -1171,11 +1171,11 @@ Error:
                         {
                             goto LError;
                         }
-                        lwZone = -(int32)(ch - 'a' + (ch < 'j')) * 60;
+                        lwZone = (int32)(ch - 'a' + (ch < 'j')) * 60;
                     }
                     else if (ch <= 'y')
                     {
-                        lwZone = (int32)(ch - 'm') * 60;
+                        lwZone = -(int32)(ch - 'm') * 60;
                     }
                     else if (ch == 'z')
                     {

+ 50 - 0
test/Date/MilitaryTimeZone.js

@@ -0,0 +1,50 @@
+//-------------------------------------------------------------------------------------------------------
+// Copyright (C) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
+//-------------------------------------------------------------------------------------------------------
+
+// See: https://github.com/Microsoft/ChakraCore/pull/4016
+// Test interpretation of military time zone
+runTest("2011-11-08 19:48:43a", "2011-11-08T19:48:43.000+01:00");
+runTest("2011-11-08 19:48:43 a", "2011-11-08T19:48:43.000+01:00");
+runTest("2011-11-08 19:48:43 b", "2011-11-08T19:48:43.000+02:00");
+runTest("2011-11-08 19:48:43 c", "2011-11-08T19:48:43.000+03:00");
+runTest("2011-11-08 19:48:43 d", "2011-11-08T19:48:43.000+04:00");
+runTest("2011-11-08 19:48:43 e", "2011-11-08T19:48:43.000+05:00");
+runTest("2011-11-08 19:48:43 f", "2011-11-08T19:48:43.000+06:00");
+runTest("2011-11-08 19:48:43 g", "2011-11-08T19:48:43.000+07:00");
+runTest("2011-11-08 19:48:43 h", "2011-11-08T19:48:43.000+08:00");
+runTest("2011-11-08 19:48:43 i", "2011-11-08T19:48:43.000+09:00");
+runTest("2011-11-08 19:48:43 j", null);
+runTest("2011-11-08 19:48:43 k", "2011-11-08T19:48:43.000+10:00");
+runTest("2011-11-08 19:48:43 l", "2011-11-08T19:48:43.000+11:00");
+runTest("2011-11-08 19:48:43 m", "2011-11-08T19:48:43.000+12:00");
+runTest("2011-11-08 19:48:43 n", "2011-11-08T19:48:43.000-01:00");
+runTest("2011-11-08 19:48:43 o", "2011-11-08T19:48:43.000-02:00");
+runTest("2011-11-08 19:48:43 p", "2011-11-08T19:48:43.000-03:00");
+runTest("2011-11-08 19:48:43 q", "2011-11-08T19:48:43.000-04:00");
+runTest("2011-11-08 19:48:43 r", "2011-11-08T19:48:43.000-05:00");
+runTest("2011-11-08 19:48:43 s", "2011-11-08T19:48:43.000-06:00");
+runTest("2011-11-08 19:48:43 t", "2011-11-08T19:48:43.000-07:00");
+runTest("2011-11-08 19:48:43 u", "2011-11-08T19:48:43.000-08:00");
+runTest("2011-11-08 19:48:43 v", "2011-11-08T19:48:43.000-09:00");
+runTest("2011-11-08 19:48:43 w", "2011-11-08T19:48:43.000-10:00");
+runTest("2011-11-08 19:48:43 x", "2011-11-08T19:48:43.000-11:00");
+runTest("2011-11-08 19:48:43 y", "2011-11-08T19:48:43.000-12:00");
+runTest("2011-11-08 19:48:43 z", "2011-11-08T19:48:43.000Z");
+
+function runTest(dateToTest, isoDate) {
+    if (isoDate === null) {
+        if (isNaN(Date.parse(dateToTest))) {
+            console.log("PASS");
+        } else {
+            console.log("Wrong date parsing result: Date.parse(\"" + dateToTest + "\") should return NaN");
+        }
+    } else {
+        if (Date.parse(dateToTest) === Date.parse(isoDate)) {
+            console.log("PASS");
+        } else {
+            console.log("Wrong date parsing result: Date.parse(\"" + dateToTest + "\") should equal Date.parse(\"" + isoDate + "\")");
+        }
+    }
+}

+ 5 - 0
test/Date/rlexe.xml

@@ -129,4 +129,9 @@
       <tags>Slow</tags>
     </default>
   </test>
+  <test>
+    <default>
+      <files>MilitaryTimeZone.js</files>
+    </default>
+  </test>
 </regress-exe>