-
Notifications
You must be signed in to change notification settings - Fork 68
/
monday.go
635 lines (548 loc) · 24.6 KB
/
monday.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
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
package monday
import (
"fmt"
"time"
)
// internalFormatFunc is a preprocessor for default time.Format func
type internalFormatFunc func(value, layout string) string
var internalFormatFuncs = map[Locale]internalFormatFunc{
LocaleEnUS: createCommonFormatFunc(LocaleEnUS),
LocaleEnGB: createCommonFormatFunc(LocaleEnGB),
LocaleDaDK: createCommonFormatFunc(LocaleDaDK),
LocaleNlBE: createCommonFormatFunc(LocaleNlBE),
LocaleNlNL: createCommonFormatFunc(LocaleNlNL),
LocaleFrFR: createCommonFormatFunc(LocaleFrFR),
LocaleFrCA: createCommonFormatFunc(LocaleFrFR),
LocaleFrGP: createCommonFormatFunc(LocaleFrFR),
LocaleFrLU: createCommonFormatFunc(LocaleFrFR),
LocaleFrMQ: createCommonFormatFunc(LocaleFrFR),
LocaleFrGF: createCommonFormatFunc(LocaleFrFR),
LocaleFrRE: createCommonFormatFunc(LocaleFrFR),
LocaleRuRU: createCommonFormatFuncWithGenitive(LocaleRuRU),
LocaleFiFI: createCommonFormatFuncWithGenitive(LocaleFiFI),
LocaleDeDE: createCommonFormatFunc(LocaleDeDE),
LocaleHuHU: createCommonFormatFunc(LocaleHuHU),
LocaleItIT: createCommonFormatFunc(LocaleItIT),
LocaleNnNO: createCommonFormatFunc(LocaleNnNO),
LocaleNbNO: createCommonFormatFunc(LocaleNbNO),
LocalePlPL: createCommonFormatFuncWithGenitive(LocalePlPL),
LocalePtPT: createCommonFormatFunc(LocalePtPT),
LocalePtBR: createCommonFormatFunc(LocalePtBR),
LocaleRoRO: createCommonFormatFunc(LocaleRoRO),
LocaleEsES: createCommonFormatFunc(LocaleEsES),
LocaleCaES: createCommonFormatFunc(LocaleCaES),
LocaleSvSE: createCommonFormatFunc(LocaleSvSE),
LocaleTrTR: createCommonFormatFunc(LocaleTrTR),
LocaleUkUA: createCommonFormatFuncWithGenitive(LocaleUkUA),
LocaleBgBG: createCommonFormatFunc(LocaleBgBG),
LocaleZhCN: createCommonFormatFunc(LocaleZhCN),
LocaleZhTW: createCommonFormatFunc(LocaleZhTW),
LocaleZhHK: createCommonFormatFunc(LocaleZhHK),
LocaleKoKR: createCommonFormatFunc(LocaleKoKR),
LocaleJaJP: createCommonFormatFunc(LocaleJaJP),
LocaleElGR: createCommonFormatFuncWithGenitive(LocaleElGR),
LocaleIdID: createCommonFormatFunc(LocaleIdID),
LocaleCsCZ: createCommonFormatFunc(LocaleCsCZ),
LocaleSlSI: createCommonFormatFunc(LocaleSlSI),
LocaleLtLT: createCommonFormatFuncWithGenitive(LocaleLtLT),
LocaleEtEE: createCommonFormatFunc(LocaleEtEE),
LocaleHrHR: createCommonFormatFunc(LocaleHrHR),
LocaleLvLV: createCommonFormatFunc(LocaleLvLV),
LocaleSkSK: createCommonFormatFunc(LocaleSkSK),
LocaleThTH: createCommonFormatFunc(LocaleThTH),
LocaleUzUZ: createCommonFormatFuncWithGenitive(LocaleUzUZ),
LocaleKkKZ: createCommonFormatFuncWithGenitive(LocaleKkKZ),
}
// internalParseFunc is a preprocessor for default time.ParseInLocation func
type internalParseFunc func(layout, value string) string
var internalParseFuncs = map[Locale]internalParseFunc{
LocaleEnUS: createCommonParseFunc(LocaleEnUS),
LocaleEnGB: createCommonParseFunc(LocaleEnGB),
LocaleDaDK: createCommonParseFunc(LocaleDaDK),
LocaleNlBE: createCommonParseFunc(LocaleNlBE),
LocaleNlNL: createCommonParseFunc(LocaleNlNL),
LocaleFrFR: createCommonParseFunc(LocaleFrFR),
LocaleFrCA: createCommonParseFunc(LocaleFrFR),
LocaleFrGP: createCommonParseFunc(LocaleFrFR),
LocaleFrLU: createCommonParseFunc(LocaleFrFR),
LocaleFrMQ: createCommonParseFunc(LocaleFrFR),
LocaleFrGF: createCommonParseFunc(LocaleFrFR),
LocaleFrRE: createCommonParseFunc(LocaleFrFR),
LocaleRuRU: createCommonParseFuncWithGenitive(LocaleRuRU),
LocaleFiFI: createCommonParseFuncWithGenitive(LocaleFiFI),
LocaleDeDE: createCommonParseFunc(LocaleDeDE),
LocaleHuHU: createCommonParseFunc(LocaleHuHU),
LocaleItIT: createCommonParseFunc(LocaleItIT),
LocaleNnNO: createCommonParseFunc(LocaleNnNO),
LocaleNbNO: createCommonParseFunc(LocaleNbNO),
LocalePlPL: createCommonParseFuncWithGenitive(LocalePlPL),
LocalePtPT: parseFuncPtCommon(LocalePtPT),
LocalePtBR: parseFuncPtCommon(LocalePtBR),
LocaleRoRO: createCommonParseFunc(LocaleRoRO),
LocaleEsES: createCommonParseFunc(LocaleEsES),
LocaleCaES: createCommonParseFunc(LocaleCaES),
LocaleSvSE: createCommonParseFunc(LocaleSvSE),
LocaleTrTR: createCommonParseFunc(LocaleTrTR),
LocaleUkUA: createCommonParseFuncWithGenitive(LocaleUkUA),
LocaleBgBG: createCommonParseFunc(LocaleBgBG),
LocaleZhCN: parseFuncZhCommon(LocaleZhCN),
LocaleZhTW: parseFuncZhCommon(LocaleZhTW),
LocaleZhHK: parseFuncZhCommon(LocaleZhHK),
LocaleKoKR: parseFuncKoCommon(LocaleKoKR),
LocaleJaJP: parseFuncJaCommon(LocaleJaJP),
LocaleElGR: createCommonParseFuncWithGenitive(LocaleElGR),
LocaleIdID: createCommonParseFunc(LocaleIdID),
LocaleCsCZ: createCommonParseFunc(LocaleCsCZ),
LocaleSlSI: createCommonParseFunc(LocaleSlSI),
LocaleLtLT: createCommonParseFuncWithGenitive(LocaleLtLT),
LocaleEtEE: createCommonParseFunc(LocaleEtEE),
LocaleHrHR: createCommonParseFunc(LocaleHrHR),
LocaleLvLV: createCommonParseFunc(LocaleLvLV),
LocaleSkSK: createCommonParseFunc(LocaleSkSK),
LocaleThTH: parseFuncThCommon(LocaleThTH),
LocaleUzUZ: createCommonParseFuncWithGenitive(LocaleUzUZ),
LocaleKkKZ: createCommonParseFuncWithGenitive(LocaleKkKZ),
}
var knownDaysShort = map[Locale]map[string]string{} // Mapping for 'Format', days of week, short form
var knownDaysLong = map[Locale]map[string]string{} // Mapping for 'Format', days of week, long form
var knownMonthsLong = map[Locale]map[string]string{} // Mapping for 'Format', months: long form
var knownMonthsShort = map[Locale]map[string]string{} // Mapping for 'Format', months: short form
var knownMonthsGenitiveShort = map[Locale]map[string]string{} // Mapping for 'Format', special for names in genitive, short form
var knownMonthsGenitiveLong = map[Locale]map[string]string{} // Mapping for 'Format', special for names in genitive, long form
var knownPeriods = map[Locale]map[string]string{} // Mapping for 'Format', AM/PM
// Reverse maps for the same
var knownDaysShortReverse = map[Locale]map[string]string{} // Mapping for 'Format', days of week, short form
var knownDaysLongReverse = map[Locale]map[string]string{} // Mapping for 'Format', days of week, long form
var knownMonthsLongReverse = map[Locale]map[string]string{} // Mapping for 'Format', months: long form
var knownMonthsShortReverse = map[Locale]map[string]string{} // Mapping for 'Format', months: short form
var knownMonthsGenitiveShortReverse = map[Locale]map[string]string{} // Mapping for 'Format', special for names in genitive, short form
var knownMonthsGenitiveLongReverse = map[Locale]map[string]string{} // Mapping for 'Format', special for names in genitive, long form
var knownPeriodsReverse = map[Locale]map[string]string{} // Mapping for 'Format', AM/PM
func init() {
fillKnownWords()
}
func fillKnownWords() {
// En_US: English (United States)
fillKnownDaysLong(longDayNamesEnUS, LocaleEnUS)
fillKnownDaysShort(shortDayNamesEnUS, LocaleEnUS)
fillKnownMonthsLong(longMonthNamesEnUS, LocaleEnUS)
fillKnownMonthsShort(shortMonthNamesEnUS, LocaleEnUS)
// En_GB: English (United Kingdom)
fillKnownDaysLong(longDayNamesEnUS, LocaleEnGB)
fillKnownDaysShort(shortDayNamesEnUS, LocaleEnGB)
fillKnownMonthsLong(longMonthNamesEnUS, LocaleEnGB)
fillKnownMonthsShort(shortMonthNamesEnUS, LocaleEnGB)
// Da_DK: Danish (Denmark)
fillKnownDaysLong(longDayNamesDaDK, LocaleDaDK)
fillKnownDaysShort(shortDayNamesDaDK, LocaleDaDK)
fillKnownMonthsLong(longMonthNamesDaDK, LocaleDaDK)
fillKnownMonthsShort(shortMonthNamesDaDK, LocaleDaDK)
// Nl_BE: Dutch (Belgium)
fillKnownDaysLong(longDayNamesNlBE, LocaleNlBE)
fillKnownDaysShort(shortDayNamesNlBE, LocaleNlBE)
fillKnownMonthsLong(longMonthNamesNlBE, LocaleNlBE)
fillKnownMonthsShort(shortMonthNamesNlBE, LocaleNlBE)
// Nl_NL: Dutch (Netherlands)
fillKnownDaysLong(longDayNamesNlBE, LocaleNlNL)
fillKnownDaysShort(shortDayNamesNlBE, LocaleNlNL)
fillKnownMonthsLong(longMonthNamesNlBE, LocaleNlNL)
fillKnownMonthsShort(shortMonthNamesNlBE, LocaleNlNL)
// Fi_FI: Finnish (Finland)
fillKnownDaysLong(longDayNamesFiFI, LocaleFiFI)
fillKnownDaysShort(shortDayNamesFiFI, LocaleFiFI)
fillKnownMonthsLong(longMonthNamesFiFI, LocaleFiFI)
fillKnownMonthsShort(shortMonthNamesFiFI, LocaleFiFI)
fillKnownMonthsGenitiveLong(longMonthNamesGenitiveFiFI, LocaleFiFI)
fillKnownMonthsGenitiveShort(shortMonthNamesFiFI, LocaleFiFI)
// Fr_FR: French (France)
fillKnownDaysLong(longDayNamesFrFR, LocaleFrFR)
fillKnownDaysShort(shortDayNamesFrFR, LocaleFrFR)
fillKnownMonthsLong(longMonthNamesFrFR, LocaleFrFR)
fillKnownMonthsShort(shortMonthNamesFrFR, LocaleFrFR)
// Fr_CA: French (Canada)
fillKnownDaysLong(longDayNamesFrFR, LocaleFrCA)
fillKnownDaysShort(shortDayNamesFrFR, LocaleFrCA)
fillKnownMonthsLong(longMonthNamesFrFR, LocaleFrCA)
fillKnownMonthsShort(shortMonthNamesFrFR, LocaleFrCA)
// Fr_GP: French (Guadeloupe)
fillKnownDaysLong(longDayNamesFrFR, LocaleFrGP)
fillKnownDaysShort(shortDayNamesFrFR, LocaleFrGP)
fillKnownMonthsLong(longMonthNamesFrFR, LocaleFrGP)
fillKnownMonthsShort(shortMonthNamesFrFR, LocaleFrGP)
// Fr_LU: French (Luxembourg)
fillKnownDaysLong(longDayNamesFrFR, LocaleFrLU)
fillKnownDaysShort(longDayNamesFrFR, LocaleFrLU)
fillKnownMonthsLong(longDayNamesFrFR, LocaleFrLU)
fillKnownMonthsShort(longDayNamesFrFR, LocaleFrLU)
// Fr_MQ: French (Martinique)
fillKnownDaysLong(longDayNamesFrFR, LocaleFrMQ)
fillKnownDaysShort(longDayNamesFrFR, LocaleFrMQ)
fillKnownMonthsLong(longDayNamesFrFR, LocaleFrMQ)
fillKnownMonthsShort(longDayNamesFrFR, LocaleFrMQ)
// Fr_GF: French (French Guiana)
fillKnownDaysLong(longDayNamesFrFR, LocaleFrGF)
fillKnownDaysShort(longDayNamesFrFR, LocaleFrGF)
fillKnownMonthsLong(longDayNamesFrFR, LocaleFrGF)
fillKnownMonthsShort(longDayNamesFrFR, LocaleFrGF)
// Fr_RE: French (French Reunion)
fillKnownDaysLong(longDayNamesFrFR, LocaleFrRE)
fillKnownDaysShort(longDayNamesFrFR, LocaleFrRE)
fillKnownMonthsLong(longDayNamesFrFR, LocaleFrRE)
fillKnownMonthsShort(longDayNamesFrFR, LocaleFrRE)
// De_DE: German (Germany)
fillKnownDaysLong(longDayNamesDeDE, LocaleDeDE)
fillKnownDaysShort(shortDayNamesDeDE, LocaleDeDE)
fillKnownMonthsLong(longMonthNamesDeDE, LocaleDeDE)
fillKnownMonthsShort(shortMonthNamesDeDE, LocaleDeDE)
// Hu_HU: Hungarian (Hungary)
fillKnownDaysLong(longDayNamesHuHU, LocaleHuHU)
fillKnownDaysShort(shortDayNamesHuHU, LocaleHuHU)
fillKnownMonthsLong(longMonthNamesHuHU, LocaleHuHU)
fillKnownMonthsShort(shortMonthNamesHuHU, LocaleHuHU)
// It_IT: Italian (Italy)
fillKnownDaysLong(longDayNamesItIT, LocaleItIT)
fillKnownDaysShort(shortDayNamesItIT, LocaleItIT)
fillKnownMonthsLong(longMonthNamesItIT, LocaleItIT)
fillKnownMonthsShort(shortMonthNamesItIT, LocaleItIT)
// Nn_NO: Norwegian Nynorsk (Norway)
fillKnownDaysLong(longDayNamesNnNO, LocaleNnNO)
fillKnownDaysShort(shortDayNamesNnNO, LocaleNnNO)
fillKnownMonthsLong(longMonthNamesNnNO, LocaleNnNO)
fillKnownMonthsShort(shortMonthNamesNnNO, LocaleNnNO)
// Nb_NO: Norwegian Bokmål (Norway)
fillKnownDaysLong(longDayNamesNbNO, LocaleNbNO)
fillKnownDaysShort(shortDayNamesNbNO, LocaleNbNO)
fillKnownMonthsLong(longMonthNamesNbNO, LocaleNbNO)
fillKnownMonthsShort(shortMonthNamesNbNO, LocaleNbNO)
// Pl_PL: Polish (Poland)
fillKnownDaysLong(longDayNamesPlPL, LocalePlPL)
fillKnownDaysShort(shortDayNamesPlPL, LocalePlPL)
fillKnownMonthsLong(longMonthNamesPlPL, LocalePlPL)
fillKnownMonthsShort(shortMonthNamesPlPL, LocalePlPL)
fillKnownMonthsGenitiveLong(longMonthNamesGenitivePlPL, LocalePlPL)
fillKnownMonthsGenitiveShort(shortMonthNamesGenitivePlPL, LocalePlPL)
// Pt_PT: Portuguese (Portugal)
fillKnownDaysLong(longDayNamesPtPT, LocalePtPT)
fillKnownDaysShort(shortDayNamesPtPT, LocalePtPT)
fillKnownMonthsLong(longMonthNamesPtPT, LocalePtPT)
fillKnownMonthsShort(shortMonthNamesPtPT, LocalePtPT)
// Pt_BR: Portuguese (Brazil)
fillKnownDaysLong(longDayNamesPtBR, LocalePtBR)
fillKnownDaysShort(shortDayNamesPtBR, LocalePtBR)
fillKnownMonthsLong(longMonthNamesPtBR, LocalePtBR)
fillKnownMonthsShort(shortMonthNamesPtBR, LocalePtBR)
// Ro_RO: Romanian (Romania)
fillKnownDaysLong(longDayNamesRoRO, LocaleRoRO)
fillKnownDaysShort(shortDayNamesRoRO, LocaleRoRO)
fillKnownMonthsLong(longMonthNamesRoRO, LocaleRoRO)
fillKnownMonthsShort(shortMonthNamesRoRO, LocaleRoRO)
// Ru_RU: Russian (Russia)
fillKnownDaysLong(longDayNamesRuRU, LocaleRuRU)
fillKnownDaysShort(shortDayNamesRuRU, LocaleRuRU)
fillKnownMonthsLong(longMonthNamesRuRU, LocaleRuRU)
fillKnownMonthsShort(shortMonthNamesRuRU, LocaleRuRU)
fillKnownMonthsGenitiveLong(longMonthNamesGenitiveRuRU, LocaleRuRU)
fillKnownMonthsGenitiveShort(shortMonthNamesGenitiveRuRU, LocaleRuRU)
// Es_ES: Spanish (Spain)
fillKnownDaysLong(longDayNamesEsES, LocaleEsES)
fillKnownDaysShort(shortDayNamesEsES, LocaleEsES)
fillKnownMonthsLong(longMonthNamesEsES, LocaleEsES)
fillKnownMonthsShort(shortMonthNamesEsES, LocaleEsES)
// Ca_ES: Catalan (Spain)
fillKnownDaysLong(longDayNamesCaES, LocaleCaES)
fillKnownDaysShort(shortDayNamesCaES, LocaleCaES)
fillKnownMonthsLong(longMonthNamesCaES, LocaleCaES)
fillKnownMonthsShort(shortMonthNamesCaES, LocaleCaES)
// Sv_SE: Swedish (Sweden)
fillKnownDaysLong(longDayNamesSvSE, LocaleSvSE)
fillKnownDaysShort(shortDayNamesSvSE, LocaleSvSE)
fillKnownMonthsLong(longMonthNamesSvSE, LocaleSvSE)
fillKnownMonthsShort(shortMonthNamesSvSE, LocaleSvSE)
// Tr_TR: Turkish (Turkey)
fillKnownDaysLong(longDayNamesTrTR, LocaleTrTR)
fillKnownDaysShort(shortDayNamesTrTR, LocaleTrTR)
fillKnownMonthsLong(longMonthNamesTrTR, LocaleTrTR)
fillKnownMonthsShort(shortMonthNamesTrTR, LocaleTrTR)
// Uk_UA: Ukrainian (Ukraine)
fillKnownDaysLong(longDayNamesUkUA, LocaleUkUA)
fillKnownDaysShort(shortDayNamesUkUA, LocaleUkUA)
fillKnownMonthsLong(longMonthNamesUkUA, LocaleUkUA)
fillKnownMonthsShort(shortMonthNamesUkUA, LocaleUkUA)
fillKnownMonthsGenitiveLong(longMonthNamesGenitiveUkUA, LocaleUkUA)
fillKnownMonthsGenitiveShort(shortMonthNamesGenitiveUkUA, LocaleUkUA)
// Bg_BG: Bulgarian (Bulgaria)
fillKnownDaysLong(longDayNamesBgBG, LocaleBgBG)
fillKnownDaysShort(shortDayNamesBgBG, LocaleBgBG)
fillKnownMonthsLong(longMonthNamesBgBG, LocaleBgBG)
fillKnownMonthsShort(shortMonthNamesBgBG, LocaleBgBG)
// Zh_CN: Chinese (Mainland)
fillKnownDaysLong(longDayNamesZhCN, LocaleZhCN)
fillKnownDaysShort(shortDayNamesZhCN, LocaleZhCN)
fillKnownMonthsLong(longMonthNamesZhCN, LocaleZhCN)
fillKnownMonthsShort(shortMonthNamesZhCN, LocaleZhCN)
// Zh_TW: Chinese (Taiwan)
fillKnownDaysLong(longDayNamesZhTW, LocaleZhTW)
fillKnownDaysShort(shortDayNamesZhTW, LocaleZhTW)
fillKnownMonthsLong(longMonthNamesZhTW, LocaleZhTW)
fillKnownMonthsShort(shortMonthNamesZhTW, LocaleZhTW)
// Zh_HK: Chinese (Hong Kong)
fillKnownDaysLong(longDayNamesZhHK, LocaleZhHK)
fillKnownDaysShort(shortDayNamesZhHK, LocaleZhHK)
fillKnownMonthsLong(longMonthNamesZhHK, LocaleZhHK)
fillKnownMonthsShort(shortMonthNamesZhHK, LocaleZhHK)
// Ko_KR: Korean (Korea)
fillKnownDaysLong(longDayNamesKoKR, LocaleKoKR)
fillKnownDaysShort(shortDayNamesKoKR, LocaleKoKR)
fillKnownMonthsLong(longMonthNamesKoKR, LocaleKoKR)
fillKnownMonthsShort(shortMonthNamesKoKR, LocaleKoKR)
fillKnownPeriods(periodsKoKR, LocaleKoKR)
// Ja_JP: Japanese (Japan)
fillKnownDaysLong(longDayNamesJaJP, LocaleJaJP)
fillKnownDaysShort(shortDayNamesJaJP, LocaleJaJP)
fillKnownMonthsLong(longMonthNamesJaJP, LocaleJaJP)
fillKnownMonthsShort(shortMonthNamesJaJP, LocaleJaJP)
fillKnownPeriods(periodsJaJP, LocaleJaJP)
// El_GR: Greek (Greece)
fillKnownDaysLong(longDayNamesElGR, LocaleElGR)
fillKnownDaysShort(shortDayNamesElGR, LocaleElGR)
fillKnownMonthsLong(longMonthNamesElGR, LocaleElGR)
fillKnownMonthsShort(shortMonthNamesElGR, LocaleElGR)
fillKnownMonthsGenitiveLong(longMonthNamesGenitiveElGR, LocaleElGR)
fillKnownMonthsGenitiveShort(shortMonthNamesElGR, LocaleElGR)
fillKnownPeriods(periodsElGR, LocaleElGR)
// Id_ID: Indonesia (Indonesia)
fillKnownDaysLong(longDayNamesIdID, LocaleIdID)
fillKnownDaysShort(shortDayNamesIdID, LocaleIdID)
fillKnownMonthsLong(longMonthNamesIdID, LocaleIdID)
fillKnownMonthsShort(shortMonthNamesIdID, LocaleIdID)
// Cs_CZ: Czech (Czech Republic)
fillKnownDaysLong(longDayNamesCsCZ, LocaleCsCZ)
fillKnownDaysShort(shortDayNamesCsCZ, LocaleCsCZ)
fillKnownMonthsLong(longMonthNamesCsCZ, LocaleCsCZ)
fillKnownMonthsShort(shortMonthNamesCsCZ, LocaleCsCZ)
// Sl_SI: Slovenian (Slovenia)
fillKnownDaysLong(longDayNamesSlSI, LocaleSlSI)
fillKnownDaysShort(shortDayNamesSlSI, LocaleSlSI)
fillKnownMonthsLong(longMonthNamesSlSI, LocaleSlSI)
fillKnownMonthsShort(shortMonthNamesSlSI, LocaleSlSI)
// Lt_LT: Lithuanian (Lithuania)
fillKnownDaysLong(longDayNamesLtLT, LocaleLtLT)
fillKnownDaysShort(shortDayNamesLtLT, LocaleLtLT)
fillKnownMonthsLong(longMonthNamesLtLT, LocaleLtLT)
fillKnownMonthsShort(shortMonthNamesLtLT, LocaleLtLT)
fillKnownMonthsGenitiveLong(longMonthNamesGenitiveLtLT, LocaleLtLT)
fillKnownMonthsGenitiveShort(shortMonthNamesGenitiveLtLT, LocaleLtLT)
// Et_EE: Estonian (Estonia)
fillKnownDaysLong(longDayNamesEtEE, LocaleEtEE)
fillKnownDaysShort(shortDayNamesEtEE, LocaleEtEE)
fillKnownMonthsLong(longMonthNamesEtEE, LocaleEtEE)
fillKnownMonthsShort(shortMonthNamesEtEE, LocaleEtEE)
// Hr_HR: Croatian (Croatia)
fillKnownDaysLong(longDayNamesHrHR, LocaleHrHR)
fillKnownDaysShort(shortDayNamesHrHR, LocaleHrHR)
fillKnownMonthsLong(longMonthNamesHrHR, LocaleHrHR)
fillKnownMonthsShort(shortMonthNamesHrHR, LocaleHrHR)
// Lv_LV: Latvian (Latvia)
fillKnownDaysLong(longDayNamesLvLV, LocaleLvLV)
fillKnownDaysShort(shortDayNamesLvLV, LocaleLvLV)
fillKnownMonthsLong(longMonthNamesLvLV, LocaleLvLV)
fillKnownMonthsShort(shortMonthNamesLvLV, LocaleLvLV)
// Sk_SK: Slovak (Slovakia)
fillKnownDaysLong(longDayNamesSkSK, LocaleSkSK)
fillKnownDaysShort(shortDayNamesSkSK, LocaleSkSK)
fillKnownMonthsLong(longMonthNamesSkSK, LocaleSkSK)
fillKnownMonthsShort(shortMonthNamesSkSK, LocaleSkSK)
// Th_TH: Thai (Thailand)
fillKnownDaysLong(longDayNamesThTH, LocaleThTH)
fillKnownDaysShort(shortDayNamesThTH, LocaleThTH)
fillKnownMonthsLong(longMonthNamesThTH, LocaleThTH)
fillKnownMonthsShort(shortMonthNamesThTH, LocaleThTH)
// Uz_UZ: Uzbek (Uzbekistan)
fillKnownDaysLong(longDayNamesUzUZ, LocaleUzUZ)
fillKnownDaysShort(shortDayNamesUzUZ, LocaleUzUZ)
fillKnownMonthsLong(longMonthNamesUzUZ, LocaleUzUZ)
fillKnownMonthsShort(shortMonthNamesUzUZ, LocaleUzUZ)
fillKnownMonthsGenitiveLong(longMonthNamesGenitiveUzUZ, LocaleUzUZ)
fillKnownMonthsGenitiveShort(shortMonthNamesGenitiveUzUZ, LocaleUzUZ)
// Kk_KZ: Kazakh (Kazakhstan)
fillKnownDaysLong(longDayNamesKkKZ, LocaleKkKZ)
fillKnownDaysShort(shortDayNamesKkKZ, LocaleKkKZ)
fillKnownMonthsLong(longMonthNamesKkKZ, LocaleKkKZ)
fillKnownMonthsShort(shortMonthNamesKkKZ, LocaleKkKZ)
fillKnownMonthsGenitiveLong(longMonthNamesGenitiveKkKZ, LocaleKkKZ)
fillKnownMonthsGenitiveShort(shortMonthNamesGenitiveKkKZ, LocaleKkKZ)
}
func fill(src map[string]string, dest map[Locale]map[string]string, locale Locale) {
loc, ok := dest[locale]
if !ok {
loc = make(map[string]string, len(src))
dest[locale] = loc
}
for k, v := range src {
loc[k] = v
}
}
func fillReverse(src map[string]string, dest map[Locale]map[string]string, locale Locale) {
loc, ok := dest[locale]
if !ok {
loc = make(map[string]string, len(src))
dest[locale] = loc
}
for k, v := range src {
loc[v] = k
}
}
func fillKnownMonthsGenitiveShort(src map[string]string, locale Locale) {
fillReverse(src, knownMonthsGenitiveShortReverse, locale)
fill(src, knownMonthsGenitiveShort, locale)
}
func fillKnownMonthsGenitiveLong(src map[string]string, locale Locale) {
fillReverse(src, knownMonthsGenitiveLongReverse, locale)
fill(src, knownMonthsGenitiveLong, locale)
}
func fillKnownDaysShort(src map[string]string, locale Locale) {
fillReverse(src, knownDaysShortReverse, locale)
fill(src, knownDaysShort, locale)
}
func fillKnownDaysLong(src map[string]string, locale Locale) {
fillReverse(src, knownDaysLongReverse, locale)
fill(src, knownDaysLong, locale)
}
func fillKnownMonthsShort(src map[string]string, locale Locale) {
fillReverse(src, knownMonthsShortReverse, locale)
fill(src, knownMonthsShort, locale)
}
func fillKnownMonthsLong(src map[string]string, locale Locale) {
fillReverse(src, knownMonthsLongReverse, locale)
fill(src, knownMonthsLong, locale)
}
func fillKnownPeriods(src map[string]string, locale Locale) {
fillReverse(src, knownPeriodsReverse, locale)
fill(src, knownPeriods, locale)
}
// Format is the standard time.Format wrapper, that replaces known standard 'time' package
// identifiers for months and days to their equivalents in the specified language.
//
// Values of variables 'longDayNames', 'shortDayNames', 'longMonthNames', 'shortMonthNames'
// from file 'time/format.go' (revision 'go1') are chosen as the 'known' words.
//
// Some languages have specific behavior, e.g. in Russian language
// month names have different suffix when they are presented stand-alone (i.e. in a list or something)
// and yet another one when they are part of a formatted date.
// So, even though March is "Март" in Russian, correctly formatted today's date would be: "7 марта 2007".
// Thus, some transformations for some languages may be a bit more complex than just plain replacements.
func Format(dt time.Time, layout string, locale Locale) string {
fm := dt.Format(layout)
intFunc, ok := internalFormatFuncs[locale]
if !ok {
return fm
}
return intFunc(fm, layout)
}
// ParseInLocation is the standard time.ParseInLocation wrapper, which replaces
// known month/day translations for a specified locale back to English before
// calling time.ParseInLocation. So, you can parse localized dates with this wrapper.
func ParseInLocation(layout, value string, loc *time.Location, locale Locale) (time.Time, error) {
intFunc, ok := internalParseFuncs[locale]
if ok {
value = intFunc(layout, value)
} else {
return time.Now(), fmt.Errorf("unsupported locale: %v", locale)
}
return time.ParseInLocation(layout, value, loc)
}
// Parse is the standard time.Parse wrapper, which replaces
// known month/day translations for a specified locale back to English before
// calling time.Parse.
func Parse(layout, value string, locale Locale) (time.Time, error) {
intFunc, ok := internalParseFuncs[locale]
if ok {
value = intFunc(layout, value)
} else {
return time.Now(), fmt.Errorf("unsupported locale: %v", locale)
}
return time.Parse(layout, value)
}
// GetShortDays retrieves the list of days for the given locale.
// "Short" days are abbreviated versions of the full day names. In English,
// for example, this might return "Tues" for "Tuesday". For certain locales,
// the long and short form of the days of the week may be the same.
//
// If the locale cannot be found, the resulting slice will be nil.
func GetShortDays(locale Locale) []string {
days, ok := knownDaysShort[locale]
if !ok {
return nil
}
var dayOrder []string
// according to https://www.timeanddate.com/calendar/days/monday.html
// only Canada, USA and Japan use Sunday as first day of the week
switch locale {
case LocaleEnUS, LocaleJaJP:
dayOrder = dayShortOrderSundayFirst
default:
dayOrder = dayShortOrderMondayFirst
}
ret := make([]string, 0, len(days))
for _, day := range dayOrder {
ret = append(ret, days[day])
}
return ret
}
// GetShortMonths retrieves the list of months for the given locale.
// "Short" months are abbreviated versions of the full month names. In
// English, for example, this might return "Jan" for "January". For
// certain locales, the long and short form of the months may be the same.
//
// If the locale cannot be found, the resulting slice will be nil.
func GetShortMonths(locale Locale) []string {
months, ok := knownMonthsShort[locale]
if !ok {
return nil
}
ret := make([]string, 0, len(months))
for _, m := range monthShortOrder {
ret = append(ret, months[m])
}
return ret
}
// GetLongDays retrieves the list of days for the given locale. It will return
// the full name of the days of the week.
//
// If the locale cannot be found, the resulting slice will be nil.
func GetLongDays(locale Locale) []string {
days, ok := knownDaysLong[locale]
if !ok {
return nil
}
var dayOrder []string
// according to https://www.timeanddate.com/calendar/days/monday.html
// only Canada, USA and Japan use Sunday as first day of the week
switch locale {
case LocaleEnUS, LocaleJaJP:
dayOrder = dayLongOrderSundayFirst
default:
dayOrder = dayLongOrderMondayFirst
}
ret := make([]string, 0, len(days))
for _, day := range dayOrder {
ret = append(ret, days[day])
}
return ret
}
// GetLongMonths retrieves the list of months for the given locale. In
// contrast to the "short" version of this function, this functions returns
// the full name of the month.
//
// If the locale cannot be found, the resulting slice will be nil.
func GetLongMonths(locale Locale) []string {
months, ok := knownMonthsLong[locale]
if !ok {
return nil
}
ret := make([]string, 0, len(months))
for _, m := range monthLongOrder {
ret = append(ret, months[m])
}
return ret
}