-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconst.go
376 lines (295 loc) · 17 KB
/
const.go
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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
package timefy
import (
"regexp"
"time"
)
type TimeRFC string
type TimeFormatRFC string
type ZoneRFC string
// WeekStartDay set week start day, default is sunday
var WeekStartDay = time.Sunday
// DefaultConfig default config
var DefaultConfig *Config
const (
// Time in format 15:04:05,
// e.g., 13:45:30
TimeRFC01T150405 TimeRFC = "15:04:05"
// Time in format 15.04.05,
// e.g., 13.45.30
TimeRFC02D150405 TimeRFC = "15.04.05"
// Time in format 15-04-05,
// e.g., 13-45-30
TimeRFC03H150405 TimeRFC = "15-04-05"
// Time in format 15/04/05,
// e.g., 13/45/30
TimeRFC04M150405 TimeRFC = "15/04/05"
// Time in format 15 04 05,
// e.g., 13 45 30
TimeRFC05S150405 TimeRFC = "15 04 05"
// Time in format 150405,
// e.g., 134530
TimeRFC06T150405 TimeRFC = "150405"
// Time in format 15:04,
// e.g., 13:45
TimeRFC07D150405 TimeRFC = "15:04"
// Time in format 15.04,
// e.g., 13.45
TimeRFC08H150405 TimeRFC = "15.04"
// Time in format 15-04,
// e.g., 13-45
TimeRFC09M150405 TimeRFC = "15-04"
// Time in format 15/04,
// e.g., 13/45
TimeRFC10S150405 TimeRFC = "15/04"
// Time in format 1504,
// e.g., 1345
TimeRFC11T150405 TimeRFC = "1504"
)
const (
// Time in format 2006-01-02T15:04:05.999999,
// e.g., 2023-08-15T13:45:30.123456
TimeFormat20060102T150405999999 TimeFormatRFC = "2006-01-02T15:04:05.999999"
// Time in format 2006-01-02T15:04:05,
// e.g., 2023-08-15T13:45:30
TimeFormat20060102T150405 TimeFormatRFC = "2006-01-02T15:04:05"
// Time in format 2006-01-02 15:04:05,
// e.g., 2023-08-15 13:45:30
TimeFormat20060102150405 TimeFormatRFC = "2006-01-02 15:04:05"
// Time in format 02-01-2006 15:04:05,
// e.g., 15-08-2023 13:45:30
TimeFormat02012006150405 TimeFormatRFC = "02-01-2006 15:04:05"
// Time in format 02/01/2006 15:04:05,
// e.g., 15/08/2023 13:45:30
TimeFormatRFC0102012006150405 TimeFormatRFC = "02/01/2006 15:04:05"
// Time in format 2006-01-02 15:04:05.999999,
// e.g., 2023-08-15 13:45:30.123456
TimeFormat20060102150405999999 TimeFormatRFC = "2006-01-02 15:04:05.999999"
// Time in format 2006-01-02 15:04:05.999999999 -07:00,
// e.g., 2023-08-15 13:45:30.123456789 -07:00
TimeFormat20060102150405999999RFC3339 TimeFormatRFC = "2006-01-02 15:04:05.999999999 -07:00"
// Time in format 2006-01-02,
// e.g., 2023-08-15
TimeFormat20060102 TimeFormatRFC = "2006-01-02"
// Time in format 02/01/2006,
// e.g., 15/08/2023
TimeFormatRFC0102012006 TimeFormatRFC = "02/01/2006"
// Time in format 2006-01-02 15:04,
// e.g., 2023-08-15 13:45
TimeFormat200601021504 TimeFormatRFC = "2006-01-02 15:04"
// Time in format 2006-01-02 15,
// e.g., 2023-08-15 13
TimeFormat2006010215 TimeFormatRFC = "2006-01-02 15"
// Time in format 2006-01,
// e.g., 2023-08
TimeFormat200601 TimeFormatRFC = "2006-01"
// Time in format 02-01-2006,
// e.g., 15-08-2023
TimeFormat02012006 TimeFormatRFC = "02-01-2006"
// Time in format 01-02-2006,
// e.g., 08-15-2023
TimeFormat01022006 TimeFormatRFC = "01-02-2006"
// Time in format 2006-01-02 15:04:05 -07:00,
// e.g., 2023-08-15 13:45:30 -07:00
TimeFormat20060102150405Z0700 TimeFormatRFC = "2006-01-02 15:04:05 -07:00"
// Time in format 2006-01-02 15:04:05 -07:00:00,
// e.g., 2023-08-15 13:45:30 -07:00:00
TimeFormat20060102150405Z070000 TimeFormatRFC = "2006-01-02 15:04:05 -07:00:00"
// Time in format 2006-01-02T15:04:05-07:00,
// e.g., 2023-08-15T13:45:30-07:00
TimeFormat20060102150405Z0700RFC3339 TimeFormatRFC = "2006-01-02T15:04:05-07:00"
// Time in format 2006-01-02T15:04:05-07:00:00,
// e.g., 2023-08-15T13:45:30-07:00:00
TimeFormat20060102150405Z070000RFC3339 TimeFormatRFC = "2006-01-02T15:04:05-07:00:00"
// Time in format 2006-01-02 15:04:05 -07,
// e.g., 2023-08-15 13:45:30 -07
TimeFormat20060102150405Z07 TimeFormatRFC = "2006-01-02 15:04:05 -07"
// Time in format 2006-01-02T15:04:05-07,
// e.g., 2023-08-15T13:45:30-07
TimeFormat20060102150405Z07RFC3339 TimeFormatRFC = "2006-01-02T15:04:05-07"
// Time in format Mon, 02 Jan 2006 15:04:05 -0700,
// e.g., Tue, 15 Aug 2023 13:45:30 -0700
TimeFormat20060102150405Z0700RFC1123 TimeFormatRFC = "Mon, 02 Jan 2006 15:04:05 -0700"
// Time in format Mon, 02 Jan 2006 15:04:05 -07:00:00,
// e.g., Tue, 15 Aug 2023 13:45:30 -07:00:00
TimeFormat20060102150405Z070000RFC1123 TimeFormatRFC = "Mon, 02 Jan 2006 15:04:05 -07:00:00"
// Time in format Mon, 02 Jan 2006 15:04:05 -07,
// e.g., Tue, 15 Aug 2023 13:45:30 -07
TimeFormat20060102150405Z07RFC1123 TimeFormatRFC = "Mon, 02 Jan 2006 15:04:05 -07"
// Time in format 2006-01-02 15:04:05 UTC-07,
// e.g., 2023-08-15 13:45:30 UTC-07
TimeFormat20060102150405Z07UTC TimeFormatRFC = "2006-01-02 15:04:05 UTC-07"
// Time in format 2006-01-02 15:04:05 UTC-07:00,
// e.g., 2023-08-15 13:45:30 UTC-07:00
TimeFormat20060102150405Z0700UTC TimeFormatRFC = "2006-01-02 15:04:05 UTC-07:00"
// Time in format 2006-01-02 15:04:05 UTC-07:00:00,
// e.g., 2023-08-15 13:45:30 UTC-07:00:00
TimeFormat20060102150405Z070000UTC TimeFormatRFC = "2006-01-02 15:04:05 UTC-07:00:00"
// Time in format 2006-01-02T15:04:05UTC-07,
// e.g., 2023-08-15T13:45:30UTC-07
TimeFormat20060102150405Z07UTCRFC3339 TimeFormatRFC = "2006-01-02T15:04:05UTC-07"
// Time in format 2006-01-02T15:04:05UTC-07:00,
// e.g., 2023-08-15T13:45:30UTC-07:00
TimeFormat20060102150405Z0700UTCRFC3339 TimeFormatRFC = "2006-01-02T15:04:05UTC-07:00"
// Time in format 2006-01-02T15:04:05UTC-07:00:00,
// e.g., 2023-08-15T13:45:30UTC-07:00:00
TimeFormat20060102150405Z070000UTCRFC3339 TimeFormatRFC = "2006-01-02T15:04:05UTC-07:00:00"
)
// Timezone constants representing default timezones for specific regions.
const (
// DefaultTimezoneVietnam is a constant that holds the IANA Time Zone identifier
// for the default timezone in Vietnam, which is "Asia/Ho_Chi_Minh".
DefaultTimezoneVietnam ZoneRFC = "Asia/Ho_Chi_Minh"
// DefaultTimezoneNewYork is a constant that holds the IANA Time Zone identifier
// for the default timezone in New York, USA, which is "America/New_York".
DefaultTimezoneNewYork ZoneRFC = "America/New_York"
// DefaultTimezoneLondon is a constant that holds the IANA Time Zone identifier
// for the default timezone in London, United Kingdom, which is "Europe/London".
DefaultTimezoneLondon ZoneRFC = "Europe/London"
// DefaultTimezoneTokyo is a constant that holds the IANA Time Zone identifier
// for the default timezone in Tokyo, Japan, which is "Asia/Tokyo".
DefaultTimezoneTokyo ZoneRFC = "Asia/Tokyo"
// DefaultTimezoneSydney is a constant that holds the IANA Time Zone identifier
// for the default timezone in Sydney, Australia, which is "Australia/Sydney".
DefaultTimezoneSydney ZoneRFC = "Australia/Sydney"
// DefaultTimezoneParis is a constant that holds the IANA Time Zone identifier
// for the default timezone in Paris, France, which is "Europe/Paris".
DefaultTimezoneParis ZoneRFC = "Europe/Paris"
// DefaultTimezoneMoscow is a constant that holds the IANA Time Zone identifier
// for the default timezone in Moscow, Russia, which is "Europe/Moscow".
DefaultTimezoneMoscow ZoneRFC = "Europe/Moscow"
// DefaultTimezoneLosAngeles is a constant that holds the IANA Time Zone identifier
// for the default timezone in Los Angeles, USA, which is "America/Los_Angeles".
DefaultTimezoneLosAngeles ZoneRFC = "America/Los_Angeles"
// DefaultTimezoneManila is a constant that holds the IANA Time Zone identifier
// for the default timezone in Manila, Philippines, which is "Asia/Manila".
DefaultTimezoneManila ZoneRFC = "Asia/Manila"
// DefaultTimezoneKualaLumpur is a constant that holds the IANA Time Zone identifier
// for the default timezone in Kuala Lumpur, Malaysia, which is "Asia/Kuala_Lumpur".
DefaultTimezoneKualaLumpur ZoneRFC = "Asia/Kuala_Lumpur"
// DefaultTimezoneJakarta is a constant that holds the IANA Time Zone identifier
// for the default timezone in Jakarta, Indonesia, which is "Asia/Jakarta".
DefaultTimezoneJakarta ZoneRFC = "Asia/Jakarta"
// DefaultTimezoneYangon is a constant that holds the IANA Time Zone identifier
// for the default timezone in Yangon, Myanmar, which is "Asia/Yangon".
DefaultTimezoneYangon ZoneRFC = "Asia/Yangon"
// DefaultTimezoneAuckland is a constant that holds the IANA Time Zone identifier
// for the default timezone in Auckland, New Zealand, which is "Pacific/Auckland".
DefaultTimezoneAuckland ZoneRFC = "Pacific/Auckland"
// DefaultTimezoneBangkok is a constant that holds the IANA Time Zone identifier
// for the default timezone in Bangkok, Thailand, which is "Asia/Bangkok".
DefaultTimezoneBangkok ZoneRFC = "Asia/Bangkok"
// DefaultTimezoneDelhi is a constant that holds the IANA Time Zone identifier
// for the default timezone in Delhi, India, which is "Asia/Kolkata".
DefaultTimezoneDelhi ZoneRFC = "Asia/Kolkata"
// DefaultTimezoneDubai is a constant that holds the IANA Time Zone identifier
// for the default timezone in Dubai, United Arab Emirates, which is "Asia/Dubai".
DefaultTimezoneDubai ZoneRFC = "Asia/Dubai"
// DefaultTimezoneCairo is a constant that holds the IANA Time Zone identifier
// for the default timezone in Cairo, Egypt, which is "Africa/Cairo".
DefaultTimezoneCairo ZoneRFC = "Africa/Cairo"
// DefaultTimezoneAthens is a constant that holds the IANA Time Zone identifier
// for the default timezone in Athens, Greece, which is "Europe/Athens".
DefaultTimezoneAthens ZoneRFC = "Europe/Athens"
// DefaultTimezoneRome is a constant that holds the IANA Time Zone identifier
// for the default timezone in Rome, Italy, which is "Europe/Rome".
DefaultTimezoneRome ZoneRFC = "Europe/Rome"
// DefaultTimezoneJohannesburg is a constant that holds the IANA Time Zone identifier
// for the default timezone in Johannesburg, South Africa, which is "Africa/Johannesburg".
DefaultTimezoneJohannesburg ZoneRFC = "Africa/Johannesburg"
// DefaultTimezoneStockholm is a constant that holds the IANA Time Zone identifier
// for the default timezone in Stockholm, Sweden, which is "Europe/Stockholm".
DefaultTimezoneStockholm ZoneRFC = "Europe/Stockholm"
// DefaultTimezoneOslo is a constant that holds the IANA Time Zone identifier
// for the default timezone in Oslo, Norway, which is "Europe/Oslo".
DefaultTimezoneOslo ZoneRFC = "Europe/Oslo"
// DefaultTimezoneHelsinki is a constant that holds the IANA Time Zone identifier
// for the default timezone in Helsinki, Finland, which is "Europe/Helsinki".
DefaultTimezoneHelsinki ZoneRFC = "Europe/Helsinki"
// DefaultTimezoneKiev is a constant that holds the IANA Time Zone identifier
// for the default timezone in Kiev, Ukraine, which is "Europe/Kiev".
DefaultTimezoneKiev ZoneRFC = "Europe/Kiev"
// DefaultTimezoneBeijing is a constant that holds the IANA Time Zone identifier
// for the default timezone in Beijing, China, which is "Asia/Shanghai".
DefaultTimezoneBeijing ZoneRFC = "Asia/Shanghai"
// DefaultTimezoneSingapore is a constant that holds the IANA Time Zone identifier
// for the default timezone in Singapore, which is "Asia/Singapore".
DefaultTimezoneSingapore ZoneRFC = "Asia/Singapore"
// DefaultTimezoneIslamabad is a constant that holds the IANA Time Zone identifier
// for the default timezone in Islamabad, Pakistan, which is "Asia/Karachi".
DefaultTimezoneIslamabad ZoneRFC = "Asia/Karachi"
// DefaultTimezoneColombo is a constant that holds the IANA Time Zone identifier
// for the default timezone in Colombo, Sri Lanka, which is "Asia/Colombo".
DefaultTimezoneColombo ZoneRFC = "Asia/Colombo"
// DefaultTimezoneDhaka is a constant that holds the IANA Time Zone identifier
// for the default timezone in Dhaka, Bangladesh, which is "Asia/Dhaka".
DefaultTimezoneDhaka ZoneRFC = "Asia/Dhaka"
// DefaultTimezoneKathmandu is a constant that holds the IANA Time Zone identifier
// for the default timezone in Kathmandu, Nepal, which is "Asia/Kathmandu".
DefaultTimezoneKathmandu ZoneRFC = "Asia/Kathmandu"
// DefaultTimezoneBrisbane is a constant that holds the IANA Time Zone identifier
// for the default timezone in Brisbane, Australia, which is "Australia/Brisbane".
DefaultTimezoneBrisbane ZoneRFC = "Australia/Brisbane"
// DefaultTimezoneWellington is a constant that holds the IANA Time Zone identifier
// for the default timezone in Wellington, New Zealand, which is "Pacific/Auckland".
DefaultTimezoneWellington ZoneRFC = "Pacific/Auckland"
// DefaultTimezonePortMoresby is a constant that holds the IANA Time Zone identifier
// for the default timezone in Port Moresby, Papua New Guinea, which is "Pacific/Port_Moresby".
DefaultTimezonePortMoresby ZoneRFC = "Pacific/Port_Moresby"
// DefaultTimezoneSuva is a constant that holds the IANA Time Zone identifier
// for the default timezone in Suva, Fiji, which is "Pacific/Fiji".
DefaultTimezoneSuva ZoneRFC = "Pacific/Fiji"
)
var (
// TimeFormatRegexp is a regular expression that matches various time formats such as:
// 15:04:05, 15:04:05.000, 15:04:05.000000, 15, 2017-01-01 15:04, 2021-07-20T00:59:10Z,
// 2021-07-20T00:59:10+08:00, 2021-07-20T00:00:10-07:00, etc.
TimeFormatRegexp = regexp.MustCompile(`(\s+|^\s*|T)\d{1,2}((:\d{1,2})*|((:\d{1,2}){2}\.(\d{3}|\d{6}|\d{9})))(\s*$|[Z+-])`)
// TimeOnlyRegexp is a regular expression that matches time formats such as:
// 15:04:05, 15, 15:04:05.000, 15:04:05.000000, etc.
TimeOnlyRegexp = regexp.MustCompile(`^\s*\d{1,2}((:\d{1,2})*|((:\d{1,2}){2}\.(\d{3}|\d{6}|\d{9})))\s*$`)
)
var (
// TimeFormats is a slice of strings that holds various time format patterns.
// These patterns can be used to parse and format time values in different layouts.
TimeFormats = []string{
"2006", // Year only, e.g., 2023
"2006-1", // Year and month, e.g., 2023-8
"2006-1-2", // Year, month, and day, e.g., 2023-8-15
"2006-1-2 15", // Year, month, day, and hour, e.g., 2023-8-15 13
"2006-1-2 15:4", // Year, month, day, hour, and minute, e.g., 2023-8-15 13:45
"2006-1-2 15:4:5", // Year, month, day, hour, minute, and second, e.g., 2023-8-15 13:45:30
"1-2", // Month and day, e.g., 8-15
"15:4:5", // Hour, minute, and second, e.g., 13:45:30
"15:4", // Hour and minute, e.g., 13:45
"15", // Hour only, e.g., 13
"15:4:5 Jan 2, 2006 MST", // Full date and time with timezone, e.g., 13:45:30 Aug 15, 2023 MST
"2006-01-02 15:04:05.999999999 -0700 MST", // Full date and time with nanoseconds and timezone, e.g., 2023-08-15 13:45:30.123456789 -0700 MST
"2006-01-02T15:04:05Z0700", // ISO 8601 format with timezone offset, e.g., 2023-08-15T13:45:30Z0700
"2006-01-02T15:04:05Z07", // ISO 8601 format with timezone offset (short), e.g., 2023-08-15T13:45:30Z07
"2006.1.2", // Year, month, and day with dots, e.g., 2023.8.15
"2006.1.2 15:04:05", // Year, month, day, and time with dots, e.g., 2023.8.15 13:45:30
"2006.01.02", // Year, month, and day with leading zeros, e.g., 2023.08.15
"2006.01.02 15:04:05", // Year, month, day, and time with leading zeros, e.g., 2023.08.15 13:45:30
"2006.01.02 15:04:05.999999999", // Full date and time with nanoseconds and leading zeros, e.g., 2023.08.15 13:45:30.123456789
"1/2/2006", // Month, day, and year with slashes, e.g., 8/15/2023
"1/2/2006 15:4:5", // Month, day, year, and time with slashes, e.g., 8/15/2023 13:45:30
"2006/01/02", // Year, month, and day with slashes, e.g., 2023/08/15
"20060102", // Year, month, and day without separators, e.g., 20230815
"2006/01/02 15:04:05", // Year, month, day, and time with slashes, e.g., 2023/08/15 13:45:30
time.ANSIC, // ANSIC format, e.g., Mon Aug 15 13:45:30 2023
time.UnixDate, // Unix date format, e.g., Mon Aug 15 13:45:30 MST 2023
time.RubyDate, // Ruby date format, e.g., Mon Aug 15 13:45:30 +0700 2023
time.RFC822, // RFC 822 format, e.g., 15 Aug 23 13:45 MST
time.RFC822Z, // RFC 822 format with numeric timezone, e.g., 15 Aug 23 13:45 -0700
time.RFC850, // RFC 850 format, e.g., Monday, 15-Aug-23 13:45:30 MST
time.RFC1123, // RFC 1123 format, e.g., Mon, 15 Aug 2023 13:45:30 MST
time.RFC1123Z, // RFC 1123 format with numeric timezone, e.g., Mon, 15 Aug 2023 13:45:30 -0700
time.RFC3339, // RFC 3339 format, e.g., 2023-08-15T13:45:30Z
time.RFC3339Nano, // RFC 3339 format with nanoseconds, e.g., 2023-08-15T13:45:30.123456789Z
time.Kitchen, // Kitchen format, e.g., 1:45PM
time.Stamp, // Stamp format, e.g., Aug 15 13:45:30
time.StampMilli, // Stamp format with milliseconds, e.g., Aug 15 13:45:30.123
time.StampMicro, // Stamp format with microseconds, e.g., Aug 15 13:45:30.123456
time.StampNano, // Stamp format with nanoseconds, e.g., Aug 15 13:45:30.123456789
}
)