Backed out changeset d05089c1e269 (bug 1822297) for causing Documentation related...
[gecko.git] / js / src / jsapi-tests / testIsISOStyleDate.cpp
blob64f05165350d895f3af6e380757bd29939d0a7ee
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
3 */
4 /* This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 #include "js/Date.h"
9 #include "jsapi-tests/tests.h"
11 const char* VALID_DATES[] = {
12 "2009",
13 "2009-05",
14 "2009-05-19",
15 "2022-02-29",
16 "2009T15:00",
17 "2009-05T15:00",
18 "2022-06-31T15:00",
19 "2009-05-19T15:00",
20 "2009-05-19T15:00:15",
21 "2009-05-19T15:00-00:00",
22 "2009-05-19T15:00:15.452",
23 "2009-05-19T15:00:15.452Z",
24 "2009-05-19T15:00:15.452+02:00",
25 "2009-05-19T15:00:15.452-02:00",
26 "-271821-04-20T00:00:00Z",
27 "+000000-01-01T00:00:00Z",
30 const char* INVALID_DATES[] = {
31 "10",
32 "20009",
33 "+20009",
34 "2009-",
35 "2009-0",
36 "2009-15",
37 "2009-02-1",
38 "2009-02-50",
39 "15:00",
40 "T15:00",
41 "9-05-19T15:00",
42 "2009-5-19T15:00",
43 "2009-05-1T15:00",
44 "2009-02-10T15",
45 "2009-05-19T15:",
46 "2009-05-19T1:00",
47 "2009-05-19T10:1",
48 "2009-05-19T60:00",
49 "2009-05-19T15:70",
50 "2009-05-19T15:00.25",
51 "2009-05-19+10:00",
52 "2009-05-19Z",
53 "2009-05-19 15:00",
54 "2009-05-19t15:00Z",
55 "2009-05-19T15:00z",
56 "2009-05-19T15:00+01",
57 "2009-05-19T10:10+1:00",
58 "2009-05-19T10:10+01:1",
59 "2009-05-19T15:00+75:00",
60 "2009-05-19T15:00+02:80",
61 "02009-05-19T15:00",
64 BEGIN_TEST(testIsISOStyleDate_success) {
65 for (const char* date : VALID_DATES) {
66 CHECK(ValidDate(date));
68 for (const char* date : INVALID_DATES) {
69 CHECK(!ValidDate(date));
72 return true;
75 bool ValidDate(const char* str) {
76 return JS::IsISOStyleDate(cx, JS::Latin1Chars(str, strlen(str)));
79 END_TEST(testIsISOStyleDate_success)