summaryrefslogtreecommitdiffstats
path: root/src/formats.h
blob: c88f7313a924e125df5e4afc40ca2ef03525a792 (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
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
/*
 * Copyright (C) 2021, 2022  P. J. McDermott
 *
 * This file is part of @
 *
 * @ is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * @ is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with @.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef FORMATS_H_
#define FORMATS_H_

/*
 * IMPORTANT:
 *
 * All of the format strings in each array must be padded with spaces to be of
 * equal lengths.
 *
 * Conversion specifications are used by both strptime() and strftime().  As
 * required by the former function, there shall be "white-space or other non-
 * alphanumeric characters between any two conversion specifications unless all
 * of the adjacent conversion specifications convert a known, fixed number of
 * characters." [POSIX]  The "^" character may be used to separate conversion
 * specifications that should be separated (by a space) when parsing and
 * adjacent when formatting for printing.  For example, " %I^%M %p " will be
 * changed to " %I %M %p " when parsing and to " %I%M %p " when formatting for
 * printing.
 */

static const char *FORMATS_DATE[] = {
	" %a             ",  /* Wed                          */
	" %a.            ",  /* Wed.                         */
	" %Y-%m-%d       ",  /* 1969-12-31                   */
	" %Y/%m/%d       ",  /* 1969/12/31                   */
	" %Y.%m.%d       ",  /* 1969.12.31                   */
	" %m-%d-%Y       ",  /* 12-31-1969                   */
	" %m-%d          ",  /* 12-31                        */
	" %m/%d/%Y       ",  /* 12/31/1969                   */
	" %m/%d          ",  /* 12/31                        */
	" %m.%d.%Y       ",  /* 12.31.1969                   */
	" %m.%d          ",  /* 12.31                        */
	" %e %b %Y       ",  /* 31 Dec 1969                  */
	" %e %b. %Y      ",  /* 31 Dec. 1969                 */
	" %e %b          ",  /* 31 Dec                       */
	" %e %b.         ",  /* 31 Dec.                      */
	" %d-%b-%Y       ",  /* 31-Dec-1969                  */
	" %d-%b          ",  /* 31-Dec                       */
	" %d/%b/%Y       ",  /* 31/Dec/1969                  */
	" %d/%b          ",  /* 31/Dec                       */
	" %a %e %b %Y    ",  /* Wed 31 Dec 1969              */
	" %a %e %b. %Y   ",  /* Wed 31 Dec. 1969             */
	" %a %e %b       ",  /* Wed 31 Dec                   */
	" %a %e %b.      ",  /* Wed 31 Dec.                  */
	" %a %d-%b-%Y    ",  /* Wed 31-Dec-1969              */
	" %a %d-%b       ",  /* Wed 31-Dec                   */
	" %a %d/%b/%Y    ",  /* Wed 31/Dec/1969              */
	" %a %d/%b       ",  /* Wed 31/Dec                   */
	" %a. %e %b %Y   ",  /* Wed. 31 Dec 1969             */
	" %a. %e %b. %Y  ",  /* Wed. 31 Dec. 1969            */
	" %a. %e %b      ",  /* Wed. 31 Dec                  */
	" %a. %e %b.     ",  /* Wed. 31 Dec.                 */
	" %a. %d-%b-%Y   ",  /* Wed. 31-Dec-1969             */
	" %a. %d-%b      ",  /* Wed. 31-Dec                  */
	" %a. %d/%b/%Y   ",  /* Wed. 31/Dec/1969             */
	" %a. %d/%b      ",  /* Wed. 31/Dec                  */
	" %a, %e %b %Y   ",  /* Wed, 31 Dec 1969             */
	" %a, %e %b. %Y  ",  /* Wed, 31 Dec. 1969            */
	" %a, %e %b      ",  /* Wed, 31 Dec                  */
	" %a, %e %b.     ",  /* Wed, 31 Dec.                 */
	" %a, %d-%b-%Y   ",  /* Wed, 31-Dec-1969             */
	" %a, %d-%b      ",  /* Wed, 31-Dec                  */
	" %a, %d/%b/%Y   ",  /* Wed, 31/Dec/1969             */
	" %a, %d/%b      ",  /* Wed, 31/Dec                  */
	" %b %e, %Y      ",  /* Dec 31, 1969                 */
	" %b. %e, %Y     ",  /* Dec. 31, 1969                */
	" %b %e          ",  /* Dec 31                       */
	" %b. %e         ",  /* Dec. 31                      */
	" %b-%d-%Y       ",  /* Dec-31-1969                  */
	" %b-%d          ",  /* Dec-31                       */
	" %b/%d/%Y       ",  /* Dec/31/1969                  */
	" %b/%d          ",  /* Dec/31                       */
	" %a %b %e, %Y   ",  /* Wed Dec 31, 1969             */
	" %a %b. %e, %Y  ",  /* Wed Dec. 31, 1969            */
	" %a %b %e       ",  /* Wed Dec 31                   */
	" %a %b. %e      ",  /* Wed Dec. 31                  */
	" %a %b-%d-%Y    ",  /* Wed Dec-31-1969              */
	" %a %b-%d       ",  /* Wed Dec-31                   */
	" %a %b/%d/%Y    ",  /* Wed Dec/31/1969              */
	" %a %b/%d       ",  /* Wed Dec/31                   */
	" %a. %b %e, %Y  ",  /* Wed. Dec 31, 1969            */
	" %a. %b. %e, %Y ",  /* Wed. Dec. 31, 1969           */
	" %a. %b %e      ",  /* Wed. Dec 31                  */
	" %a. %b. %e     ",  /* Wed. Dec. 31                 */
	" %a. %b-%d-%Y   ",  /* Wed. Dec-31-1969             */
	" %a. %b-%d      ",  /* Wed. Dec-31                  */
	" %a. %b/%d/%Y   ",  /* Wed. Dec/31/1969             */
	" %a. %b/%d      ",  /* Wed. Dec/31                  */
	" %a, %b %e, %Y  ",  /* Wed, Dec 31, 1969            */
	" %a, %b. %e, %Y ",  /* Wed, Dec. 31, 1969           */
	" %a, %b %e      ",  /* Wed, Dec 31                  */
	" %a, %b. %e     ",  /* Wed, Dec. 31                 */
	" %a, %b-%d-%Y   ",  /* Wed, Dec-31-1969             */
	" %a, %b-%d      ",  /* Wed, Dec-31                  */
	" %a, %b/%d/%Y   ",  /* Wed, Dec/31/1969             */
	" %a, %b/%d      ",  /* Wed, Dec/31                  */
	"",                  /* End of parsing formats       */
	" %A             ",  /* Wednesday                    */
	" %A %e %b %Y    ",  /* Wednesday 31 Dec 1969        */
	" %A %e %b. %Y   ",  /* Wednesday 31 Dec. 1969       */
	" %A %e %b       ",  /* Wednesday 31 Dec             */
	" %A %e %b.      ",  /* Wednesday 31 Dec.            */
	" %A %d-%b-%Y    ",  /* Wednesday 31-Dec-1969        */
	" %A %d-%b       ",  /* Wednesday 31-Dec             */
	" %A %d/%b/%Y    ",  /* Wednesday 31/Dec/1969        */
	" %A %d/%b       ",  /* Wednesday 31/Dec             */
	" %A, %e %b %Y   ",  /* Wednesday, 31 Dec 1969       */
	" %A, %e %b. %Y  ",  /* Wednesday, 31 Dec. 1969      */
	" %A, %e %b      ",  /* Wednesday, 31 Dec            */
	" %A, %e %b.     ",  /* Wednesday, 31 Dec.           */
	" %A, %d-%b-%Y   ",  /* Wednesday, 31-Dec-1969       */
	" %A, %d-%b      ",  /* Wednesday, 31-Dec            */
	" %A, %d/%b/%Y   ",  /* Wednesday, 31/Dec/1969       */
	" %A, %d/%b      ",  /* Wednesday, 31/Dec            */
	" %A %b %e, %Y   ",  /* Wednesday Dec 31, 1969       */
	" %A %b. %e, %Y  ",  /* Wednesday Dec. 31, 1969      */
	" %A %b %e       ",  /* Wednesday Dec 31             */
	" %A %b. %e      ",  /* Wednesday Dec. 31            */
	" %A %b-%d-%Y    ",  /* Wednesday Dec-31-1969        */
	" %A %b-%d       ",  /* Wednesday Dec-31             */
	" %A %b/%d/%Y    ",  /* Wednesday Dec/31/1969        */
	" %A %b/%d       ",  /* Wednesday Dec/31             */
	" %A, %b %e, %Y  ",  /* Wednesday, Dec 31, 1969      */
	" %A, %b. %e, %Y ",  /* Wednesday, Dec. 31, 1969     */
	" %A, %b %e      ",  /* Wednesday, Dec 31            */
	" %A, %b. %e     ",  /* Wednesday, Dec. 31           */
	" %A, %b-%d-%Y   ",  /* Wednesday, Dec-31-1969       */
	" %A, %b-%d      ",  /* Wednesday, Dec-31            */
	" %A, %b/%d/%Y   ",  /* Wednesday, Dec/31/1969       */
	" %A, %b/%d      ",  /* Wednesday, Dec/31            */
	" %e %B %Y       ",  /* 31 December 1969             */
	" %e %B          ",  /* 31 December                  */
	" %d-%B-%Y       ",  /* 31-December-1969             */
	" %d-%B          ",  /* 31-December                  */
	" %d/%B/%Y       ",  /* 31/December/1969             */
	" %d/%B          ",  /* 31/December                  */
	" %a %e %B %Y    ",  /* Wed 31 December 1969         */
	" %a %e %B       ",  /* Wed 31 December              */
	" %a %d-%B-%Y    ",  /* Wed 31-December-1969         */
	" %a %d-%B       ",  /* Wed 31-December              */
	" %a %d/%B/%Y    ",  /* Wed 31/December/1969         */
	" %a %d/%B       ",  /* Wed 31/December              */
	" %a. %e %B %Y   ",  /* Wed. 31 December 1969        */
	" %a. %e %B      ",  /* Wed. 31 December             */
	" %a. %d-%B-%Y   ",  /* Wed. 31-December-1969        */
	" %a. %d-%B      ",  /* Wed. 31-December             */
	" %a. %d/%B/%Y   ",  /* Wed. 31/December/1969        */
	" %a. %d/%B      ",  /* Wed. 31/December             */
	" %a, %e %B %Y   ",  /* Wed, 31 December 1969        */
	" %a, %e %B      ",  /* Wed, 31 December             */
	" %a, %d-%B-%Y   ",  /* Wed, 31-December-1969        */
	" %a, %d-%B      ",  /* Wed, 31-December             */
	" %a, %d/%B/%Y   ",  /* Wed, 31/December/1969        */
	" %a, %d/%B      ",  /* Wed, 31/December             */
	" %B %e, %Y      ",  /* December 31, 1969            */
	" %B %e          ",  /* December 31                  */
	" %B-%d-%Y       ",  /* December-31-1969             */
	" %B-%d          ",  /* December-31                  */
	" %B/%d/%Y       ",  /* December/31/1969             */
	" %B/%d          ",  /* December/31                  */
	" %a %B %e, %Y   ",  /* Wed December 31, 1969        */
	" %a %B %e       ",  /* Wed December 31              */
	" %a %B-%d-%Y    ",  /* Wed December-31-1969         */
	" %a %B-%d       ",  /* Wed December-31              */
	" %a %B/%d/%Y    ",  /* Wed December/31/1969         */
	" %a %B/%d       ",  /* Wed December/31              */
	" %a. %B %e, %Y  ",  /* Wed. December 31, 1969       */
	" %a. %B %e      ",  /* Wed. December 31             */
	" %a. %B-%d-%Y   ",  /* Wed. December-31-1969        */
	" %a. %B-%d      ",  /* Wed. December-31             */
	" %a. %B/%d/%Y   ",  /* Wed. December/31/1969        */
	" %a. %B/%d      ",  /* Wed. December/31             */
	" %a, %B %e, %Y  ",  /* Wed, December 31, 1969       */
	" %a, %B %e      ",  /* Wed, December 31             */
	" %a, %B-%d-%Y   ",  /* Wed, December-31-1969        */
	" %a, %B-%d      ",  /* Wed, December-31             */
	" %a, %B/%d/%Y   ",  /* Wed, December/31/1969        */
	" %a, %B/%d      ",  /* Wed, December/31             */
	" %A %e %B %Y    ",  /* Wednesday 31 December 1969   */
	" %A %e %B       ",  /* Wednesday 31 December        */
	" %A %d-%B-%Y    ",  /* Wednesday 31-December-1969   */
	" %A %d-%B       ",  /* Wednesday 31-December        */
	" %A %d/%B/%Y    ",  /* Wednesday 31/December/1969   */
	" %A %d/%B       ",  /* Wednesday 31/December        */
	" %A, %e %B %Y   ",  /* Wednesday, 31 December 1969  */
	" %A, %e %B      ",  /* Wednesday, 31 December       */
	" %A, %d-%B-%Y   ",  /* Wednesday, 31-December-1969  */
	" %A, %d-%B      ",  /* Wednesday, 31-December       */
	" %A, %d/%B/%Y   ",  /* Wednesday, 31/December/1969  */
	" %A, %d/%B      ",  /* Wednesday, 31/December       */
	" %A %B %e, %Y   ",  /* Wednesday December 31, 1969  */
	" %A %B %e       ",  /* Wednesday December 31        */
	" %A %B-%d-%Y    ",  /* Wednesday December-31-1969   */
	" %A %B-%d       ",  /* Wednesday December-31        */
	" %A %B/%d/%Y    ",  /* Wednesday December/31/1969   */
	" %A %B/%d       ",  /* Wednesday December/31        */
	" %A, %B %e, %Y  ",  /* Wednesday, December 31, 1969 */
	" %A, %B %e      ",  /* Wednesday, December 31       */
	" %A, %B-%d-%Y   ",  /* Wednesday, December-31-1969  */
	" %A, %B-%d      ",  /* Wednesday, December-31       */
	" %A, %B/%d/%Y   ",  /* Wednesday, December/31/1969  */
	" %A, %B/%d      ",  /* Wednesday, December/31       */
};

static const char *FORMATS_TIME[] = {
	" %I:%M:%S %p ",  /* 7:00:01 PM */
	" %H:%M:%S    ",  /* 19:00:01   */
	" %I:%M %p    ",  /* 7:00 PM    */
	" %H:%M       ",  /* 19:00      */
	" %I.%M.%S %p ",  /* 7.00.01 PM */
	" %H.%M.%S    ",  /* 19.00.01   */
	" %I.%M %p    ",  /* 7.00 PM    */
	" %H.%M       ",  /* 19.00      */
	" %I^%M^%S %p ",  /* 70001 PM   */
	" %H^%M^%S    ",  /* 190001     */
	" %I^%M %p    ",  /* 700 PM     */
	" %H^%M       ",  /* 1900       */
};

static const char *FORMATS_MISC[] = {
	/* ISO 8601: 1969-12-31 delimited by "T" */
	" %Y-%m-%dT%H:%M:%S    ",
	" %Y-%m-%dT%H:%M       ",
	/* ISO 8601: 19691231 delimited by "T" */
	" %Y^%m^%dT%H^%M^%S    ",
	" %Y^%m^%dT%H^%M       ",
	/* 19691231 */
	" %Y^%m^%d %I^%M^%S %p ",
	" %Y^%m^%d %H^%M^%S    ",
	" %Y^%m^%d %I^%M %p    ",
	" %Y^%m^%d %H^%M       ",
	/* Wed Dec 31 19:00:01 1969 */
	" %a %b %d %H:%M:%S %Y ",
};

#endif  /* FORMATS_H_ */