-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.c
More file actions
168 lines (161 loc) · 3.94 KB
/
test.c
File metadata and controls
168 lines (161 loc) · 3.94 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#include "dateparse.h"
void runtests();
void runfile();
FILE *f;
int main(int argc, char** argv){
if (argc > 1){
if (!strcmp(argv[1], "now")){
puts(datestring(nowlocal()));
puts(datestring(nowgm()));
return 0;
}
f = fopen(argv[1], "r");
if (!f) f = stdin;
runfile();
} else {
runtests();
}
return 0;
}
void runfile(){
char buf[100];
date_t d;
while(fgets(buf, 100, f)){
strtok(buf, "\n");
dateparse_2(buf, &d);
puts(datestring(d));
}
}
void runtests(){
char* dates[] = {
"May 8, 2009 5:57:51 PM",
"oct 7, 1970",
"oct 7, '70",
"oct. 7, 1970",
"oct. 7, 70",
"Mon Jan 2 15:04:05 2006",
"Mon Jan 2 15:04:05 MST 2006",
"Mon Jan 02 15:04:05 -0700 2006",
"Monday, 02-Jan-06 15:04:05 MST",
"Mon, 02 Jan 2006 15:04:05 MST",
"Tue, 11 Jul 2017 16:28:13 +0200 (CEST)",
"Mon, 02 Jan 2006 15:04:05 -0700",
"Thu, 4 Jan 2018 17:53:36 +0000",
"Mon Aug 10 15:44:11 UTC+0100 2015",
"Fri Jul 03 2015 18:04:07 GMT+0100 (GMT Daylight Time)",
"September 17, 2012 10:09am",
"September 17, 2012 at 10:09am PST-08",
"September 17, 2012, 10:10:09",
"October 7, 1970",
"October 7th, 1970",
"12 Feb 2006, 19:17",
"12 Feb 2006 19:17",
"7 oct 70",
"7 oct 1970",
"03 February 2013",
"1 July 2013",
"2013-Feb-03",
// mm/dd/yy
"3/31/2014",
"03/31/2014",
"08/21/71",
"8/1/71",
"4/8/2014 22:05",
"04/08/2014 22:05",
"4/8/14 22:05",
"04/2/2014 03:00:51",
"8/8/1965 12:00:00 AM",
"8/8/1965 01:00:01 PM",
"8/8/1965 01:00 PM",
"8/8/1965 1:00 PM",
"8/8/1965 12:00 AM",
"4/02/2014 03:00:51",
"03/19/2012 10:11:59",
"03/19/2012 10:11:59.3186369",
// yyyy/mm/dd
"2014/3/31",
"2014/03/31",
"2014/4/8 22:05",
"2014/04/08 22:05",
"2014/04/2 03:00:51",
"2014/4/02 03:00:51",
"2012/03/19 10:11:59",
"2012/03/19 10:11:59.3186369",
// yyyy-mm-ddThh
"2006-01-02T15:04:05+0000",
"2009-08-12T22:15:09-07:00",
"2009-08-12T22:15:09",
"2009-08-12T22:15:09Z",
// yyyy-mm-dd hh:mm:ss
"2014-04-26 17:24:37.3186369",
"2012-08-03 18:31:59.257000000",
"2014-04-26 17:24:37.123",
"2013-04-01 22:43",
"2013-04-01 22:43:22",
"2014-12-16 06:20:00 UTC",
"2014-12-16 06:20:00 GMT",
"2014-04-26 05:24:37 PM",
"2014-04-26 13:13:43 +0800",
"2014-04-26 13:13:43 +0800 +08",
"2014-04-26 13:13:44 +09:00",
"2012-08-03 18:31:59.257000000 +0000 UTC",
"2015-09-30 18:48:56.35272715 +0000 UTC",
"2015-02-18 00:12:00 +0000 GMT",
"2015-02-18 00:12:00 +0000 UTC",
"2015-02-08 03:02:00 +0300 MSK m=+0.000000001",
"2015-02-08 03:02:00.001 +0300 MSK m=+0.000000001",
"2017-07-19 03:21:51+00:00",
"2014-04-26",
"2014-04",
"2014",
"2014-05-11 08:20:13,787",
"1914-05-11 08:20:13,787",
"1814-05-11 08:20:13,787",
"1714-05-11 08:20:13,787",
"1614-05-11 08:20:13,787",
"1514-05-11 08:20:13,787",
"1414-05-11 08:20:13,787",
"1414-05-11 08:20:13",
"1969-12-31 08:20:13,787",
"1969-01-01 08:20:13,787",
"1968-12-31 08:20:13,787",
"1965-12-31 08:20:13,787",
"1964-12-31 08:20:13,787",
"1963-12-31 08:20:13,787",
"1962-12-31 08:20:13,787",
"1961-12-31 08:20:13,787",
"1960-12-31 08:20:13,787",
"1959-12-31 08:20:13,787",
"1958-12-31 08:20:13,787",
"1957-12-31 08:20:13,787",
// mm.dd.yy
"3.31.2014",
"03.31.2014",
"08.21.71",
"2014.03",
"2014.03.30",
// yyyymmdd and similar
"20140601",
"20140722105203",
// unix seconds, ms, micro, nano
// this gets correct time when using gmtime() instead of localtim()
"1332151919",
"1384216367189",
"1384216367111222",
"1384216367111222333",
};
int len = sizeof(dates)/sizeof(char*);
int i;
int os;
date_t d;
printf("%-63s%-24s%-11s%s\n", "date string", "parsed as", "useconds", "offset");
for (i=0; i<len; ++i){
puts("-------------------------------------------------------------------------------------------------------------");
printf("%-60s", dates[i]);
if (dateparse_3(dates[i], &d, &os)){
puts("failed");
} else {
printf(" %-24s%-12lld%d\n", datestring(d), mcs(d), os);
}
}
}