parseToUTCStringAndToISOStringResults.js 1.8 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.toUTCString() and Date.toISOString()
  6. // for negative and zero-padded years.
  7. // See https://github.com/Microsoft/ChakraCore/pull/4318
  8. /// <reference path="../UnitTestFramework/UnitTestFramework.js" />
  9. if (this.WScript && this.WScript.LoadScriptFile) { // Check for running in ch
  10. this.WScript.LoadScriptFile("..\\UnitTestFramework\\UnitTestFramework.js");
  11. }
  12. function testDate(isoDateString) {
  13. let Dateobj = new Date(isoDateString);
  14. let value = Dateobj.valueOf();
  15. let UTCstr = Dateobj.toUTCString();
  16. let ISOstr = Dateobj.toISOString();
  17. assert.areEqual(value, Date.parse(UTCstr), "Date.parse('" + UTCstr + "') returns wrong value.");
  18. assert.areEqual(value, Date.parse(ISOstr), "Date.parse('" + ISOstr + "') returns wrong value.");
  19. }
  20. let tests = [{
  21. name: "test if Date.parse() can correctly parse outputs of Date.toUTCString() and Date.toISOString()",
  22. body: function () {
  23. testDate("0001-10-13T05:16:33Z");
  24. testDate("0011-10-13T05:16:33Z");
  25. testDate("0111-10-13T05:16:33Z");
  26. testDate("1111-10-13T05:16:33Z");
  27. // test BC years
  28. testDate("-000001-11-13T19:40:33Z");
  29. testDate("-000011-11-13T19:40:33Z");
  30. testDate("-000111-11-13T19:40:33Z");
  31. testDate("-001111-11-13T19:40:33Z");
  32. }
  33. }];
  34. testRunner.run(tests, { verbose: WScript.Arguments[0] != "summary" });