parseToStringResults.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. // Date.parse must be able to parse the strings returned by Date.toString() for negative and zero-padded
  6. // years. See https://github.com/Microsoft/ChakraCore/pull/4318
  7. // This test is disabled on xplat because the time zone for negative years on xplat is different from
  8. // time zone on Windows.
  9. /// <reference path="../UnitTestFramework/UnitTestFramework.js" />
  10. if (this.WScript && this.WScript.LoadScriptFile) { // Check for running in ch
  11. this.WScript.LoadScriptFile("..\\UnitTestFramework\\UnitTestFramework.js");
  12. }
  13. function testDate(isoDateString) {
  14. let Dateobj = new Date(isoDateString);
  15. let value = Dateobj.valueOf();
  16. let str = Dateobj.toString();
  17. assert.areEqual(value, Date.parse(str), "Date.parse('" + str + "') returns wrong value.");
  18. }
  19. let tests = [{
  20. name: "test if Date.parse() can correctly parse outputs of Date.toString()",
  21. body: function () {
  22. testDate("0001-10-13T05:16:33Z");
  23. testDate("0011-10-13T05:16:33Z");
  24. testDate("0111-10-13T05:16:33Z");
  25. testDate("1111-10-13T05:16:33Z");
  26. // test BC years
  27. testDate("-000001-11-13T19:40:33Z");
  28. testDate("-000011-11-13T19:40:33Z");
  29. testDate("-000111-11-13T19:40:33Z");
  30. testDate("-001111-11-13T19:40:33Z");
  31. }
  32. }];
  33. testRunner.run(tests, { verbose: WScript.Arguments[0] != "summary" });