DateCtr.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Copyright (c) 2022 ChakraCore Project Contributors. All rights reserved.
  4. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  5. //-------------------------------------------------------------------------------------------------------
  6. var RESULTS = [
  7. "1970-01-10T00:00:01.000Z",
  8. "1974-01-01T00:00:00.000Z",
  9. "1970-01-01T00:00:01.974Z",
  10. "1974-10-01T07:00:00.000Z",
  11. "1974-10-24T07:00:00.000Z",
  12. "1974-10-24T07:00:00.000Z",
  13. "1974-10-24T07:20:00.000Z",
  14. "1974-10-24T07:20:30.000Z",
  15. "1974-10-24T07:20:30.040Z",
  16. "1974-10-24T07:20:30.040Z",
  17. "-098001-12-01T08:00:00.000Z",
  18. "1999-12-01T08:00:00.000Z",
  19. "Invalid Date",
  20. "Invalid Date",
  21. "Invalid Date" ];
  22. var index = 0;
  23. function CHECK(str)
  24. {
  25. if (str != RESULTS[index])
  26. {
  27. console.log(str + " != " + RESULTS[index]);
  28. console.log("FAIL");
  29. return false;
  30. }
  31. index++;
  32. return true;
  33. }
  34. function Test()
  35. {
  36. var d;
  37. d = new Date("Thu Jan 10 05:30:01 UTC+0530 1970"); if (!CHECK(d.toISOString())) return;
  38. d = new Date("1974"); if (!CHECK(d.toISOString())) return;
  39. d = new Date(1974); if (!CHECK(d.toISOString())) return;
  40. d = new Date(1974, 9); if (!CHECK(d.toISOString())) return;
  41. d = new Date(1974, 9, 24); if (!CHECK(d.toISOString())) return;
  42. d = new Date(1974, 9, 24, 0); if (!CHECK(d.toISOString())) return;
  43. d = new Date(1974, 9, 24, 0, 20); if (!CHECK(d.toISOString())) return;
  44. d = new Date(1974, 9, 24, 0, 20, 30); if (!CHECK(d.toISOString())) return;
  45. d = new Date(1974, 9, 24, 0, 20, 30, 40); if (!CHECK(d.toISOString())) return;
  46. d = new Date(1974, 9, 24, 0, 20, 30, 40, 50); if (!CHECK(d.toISOString())) return;
  47. if (WScript.Platform.OS == "win32") {
  48. d = new Date(2000, -1200001); if (!CHECK(d.toISOString())) return; // Make sure there is no AV for negative month (WOOB 1140748).
  49. } else {
  50. index++; // xplat DST info for BC doesn't match to Windows.
  51. }
  52. d = new Date(2000, -1); if (!CHECK(d.toISOString())) return; // Check correctness when month is negative.
  53. d = new Date("", 1e81); if (!CHECK(d + "")) return; // WOOB 1139099
  54. d = new Date(); d.setSeconds(Number.MAX_VALUE); if (!CHECK(d + "")) return; // WOOB 1142298
  55. d = new Date(); d.setSeconds(-Number.MAX_VALUE); if (!CHECK(d + "")) return; // WOOB 1142298
  56. // Issue #5442
  57. d = new Date(-0);
  58. if (!Object.is(d.getTime(), 0)) throw new Error("Expected getTime() to return +0");
  59. console.log("PASS");
  60. }
  61. Test();