summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/Date/dashed-date.js
blob: a1babf991e76af4b20229d7523d08bcc726e8e86 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
const tests = [
  // ==== Date only ====

  // dd-MMM-yyyy
  ["24-Apr-2023", "2023-04-24T00:00:00"],
  ["24-apr-2023", "2023-04-24T00:00:00"],
  ["24-April-2023", "2023-04-24T00:00:00"],
  ["24-APRIL-2023", "2023-04-24T00:00:00"],
  ["24-Apr-2033", "2033-04-24T00:00:00"],

  ["24-Apr-0023", "0023-04-24T00:00:00"],

  // dd-MMM-yy
  ["24-Apr-23", "2023-04-24T00:00:00"],
  ["24-Apr-33", "2033-04-24T00:00:00"],

  // dd-MMM-yyy
  ["24-Apr-023", "2023-04-24T00:00:00"],

  // yyyy-MM-dd
  ["2023-Apr-24", "2023-04-24T00:00:00"],
  ["2033-Apr-24", "2033-04-24T00:00:00"],

  // yy-MM-dd
  ["33-Apr-24", "2033-04-24T00:00:00"],

  // yyy-MM-dd
  ["033-Apr-24", "2033-04-24T00:00:00"],

  // ==== Date followed by hour and TZ ====

  ["24-Apr-2023 12:34:56", "2023-04-24T12:34:56"],
  ["24-Apr-2023 Mon 12:34:56", "2023-04-24T12:34:56"],
  ["24-Apr-2023 (Mon) 12:34:56", "2023-04-24T12:34:56"],
  ["24-Apr-2023(Mon)12:34:56", "2023-04-24T12:34:56"],

  ["24-Apr-2023,12:34:56", "2023-04-24T12:34:56"],
  ["24-Apr-2023,Mon 12:34:56", "2023-04-24T12:34:56"],

  ["24-Apr-2023 12:34:56 GMT", "2023-04-24T12:34:56Z"],
  ["24-Apr-2023 12:34:56 +04", "2023-04-24T12:34:56+04:00"],
  ["24-Apr-2023 12:34:56 +04:30", "2023-04-24T12:34:56+04:30"],
  ["24-Apr-2023 12:34:56 -04", "2023-04-24T12:34:56-04:00"],
  ["24-Apr-2023 12:34:56 -04:30", "2023-04-24T12:34:56-04:30"],

  ["24-Apr-2023 GMT", "2023-04-24T00:00:00Z"],
  ["24-Apr-2023 +04", "2023-04-24T00:00:00+04:00"],
  ["24-Apr-2023 +04:30", "2023-04-24T00:00:00+04:30"],
  ["24-Apr-2023 -04", "2023-04-24T00:00:00-04:00"],
  ["24-Apr-2023 -04:30", "2023-04-24T00:00:00-04:30"],

  ["24-Apr-2023GMT", "2023-04-24T00:00:00Z"],
  ["24-Apr-2023+04", "2023-04-24T00:00:00+04:00"],
  ["24-Apr-2023+04:30", "2023-04-24T00:00:00+04:30"],
  ["24-Apr-2023-04", "2023-04-24T00:00:00-04:00"],
  ["24-Apr-2023-04:30", "2023-04-24T00:00:00-04:30"],

  ["24-Apr-2023,GMT", "2023-04-24T00:00:00Z"],
  ["24-Apr-2023,+04", "2023-04-24T00:00:00+04:00"],
  ["24-Apr-2023,+04:30", "2023-04-24T00:00:00+04:30"],
  ["24-Apr-2023,-04", "2023-04-24T00:00:00-04:00"],
  ["24-Apr-2023,-04:30", "2023-04-24T00:00:00-04:30"],

  ["24-Apr-2023/12:34:56", "2023-04-24T12:34:56"],
  ["24-Apr-2023/GMT", "2023-04-24T00:00:00Z"],

  // ==== non dd-MMM-yyyy. Uses fallback path ====

  // Missing space.
  ["24-Apr-202312:13:14", "-202312-04-24T13:14:00"],

  // Extra delimiter.
  ["24-Apr- 2023", "2023-04-24T00:00:00"],
  ["24-Apr -2023", "-002023-04-24T00:00:00"],
  ["24- Apr-2023", "-002023-04-24T00:00:00"],
  ["24 -Apr-2023", "-002023-04-24T00:00:00"],

  ["24-Apr-/2023", "2023-04-24T00:00:00"],
  ["24-Apr/-2023", "-002023-04-24T00:00:00"],
  ["24-/Apr-2023", "-002023-04-24T00:00:00"],
  ["24/-Apr-2023", "-002023-04-24T00:00:00"],

  ["24-Apr-()2023", "2023-04-24T00:00:00"],
  ["24-Apr()-2023", "-002023-04-24T00:00:00"],
  ["24-()Apr-2023", "-002023-04-24T00:00:00"],
  ["24()-Apr-2023", "-002023-04-24T00:00:00"],

  // mday being 3+ digits
  ["024-Apr-2023", "-002023-04-24T00:00:00"],
  ["0024-Apr-2023", "-002023-04-24T00:00:00"],
];

for (const [testString, isoString] of tests) {
  const testDate = new Date(testString);
  const isoDate = new Date(isoString);

  assertEq(testDate.getTime(), isoDate.getTime(),
           testString);
}

const invalidTests = [
  // mday being out of range.
  "32-01-32",

  // mday being 3+ digits, while year being 2-3 digits.
  "024-Apr-22",
  "024-Apr-023",

  // Duplicate date.
  "2012-Apr-08 12/12/12",
];

for (const testString of invalidTests) {
  assertEq(Number.isNaN(new Date(testString).getTime()), true, testString);
}

if (typeof reportCompare === "function")
    reportCompare(true, true);