Passed
Pull Request — master (#13)
by Alexey
03:59
created

DateStringFormatter::formatted()   B

Complexity

Conditions 9
Paths 31

Size

Total Lines 47
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 22
CRAP Score 9.5145

Importance

Changes 0
Metric Value
eloc 27
c 0
b 0
f 0
dl 0
loc 47
ccs 22
cts 27
cp 0.8148
rs 8.0555
cc 9
nc 31
nop 2
crap 9.5145
1
<?php
2
3
/** @noinspection PhpUnusedPrivateMethodInspection */
4
declare(strict_types=1);
5
6
/**
7
 * @author   Ne-Lexa
8
 * @license  MIT
9
 *
10
 * @see      https://github.com/Ne-Lexa/google-play-scraper
11
 */
12
13
namespace Nelexa\GPlay\Util;
14
15
/**
16
 * The class for converting a localized date to the \DateTimeInterface.
17
 * It would be possible to use the php-intl library, but its different
18
 * versions give different results.
19
 *
20
 * @internal
21
 */
22
class DateStringFormatter
23
{
24
    private const MEDIUM_DATE_PATTERNS = [
25
        'af' => [
26
            'pattern' => '~^(?P<day>\d+)\s(?P<month>.*?)\s(?P<year>\d{4})$~',
27
            'months' => [
28
                'Jan.' => 1,
29
                'Feb.' => 2,
30
                'Mrt.' => 3,
31
                'Apr.' => 4,
32
                'Mei' => 5,
33
                'Jun.' => 6,
34
                'Jul.' => 7,
35
                'Aug.' => 8,
36
                'Sep.' => 9,
37
                'Okt.' => 10,
38
                'Nov.' => 11,
39
                'Des.' => 12,
40
            ],
41
        ],
42
        'am' => [
43
            'pattern' => '~^(?P<day>\d+)\s(?P<month>.*?)\s(?P<year>\d{4})~',
44
            'months' => [
45
                'ጃንዩ' => 1,
46
                'ፌብሩ' => 2,
47
                'ማርች' => 3,
48
                'ኤፕሪ' => 4,
49
                'ሜይ' => 5,
50
                'ጁን' => 6,
51
                'ጁላይ' => 7,
52
                'ኦገስ' => 8,
53
                'ሴፕቴ' => 9,
54
                'ኦክቶ' => 10,
55
                'ኖቬም' => 11,
56
                'ዲሴም' => 12,
57
            ],
58
        ],
59
        'ar' => [
60
            'pattern' => '~^(?P<day>\d{2})‏/(?P<month>\d{2})‏/(?P<year>\d{4})$~',
61
        ],
62
        'az_AZ' => [
63
            'pattern' => '~^(?P<day>\d+)\s(?P<month>.*?)\s(?P<year>\d{4})~',
64
            'months' => [
65
                'yan' => 1,
66
                'fev' => 2,
67
                'mar' => 3,
68
                'apr' => 4,
69
                'may' => 5,
70
                'iyn' => 6,
71
                'iyl' => 7,
72
                'avq' => 8,
73
                'sen' => 9,
74
                'okt' => 10,
75
                'noy' => 11,
76
                'dek' => 12,
77
            ],
78
        ],
79
        'be' => [
80
            'pattern' => '~^(?P<day>\d{1,2}) (?P<month>.*?) (?P<year>\d{4}) г.$~',
81
            'months' => [
82
                'сту' => 1,
83
                'лют' => 2,
84
                'сак' => 3,
85
                'кра' => 4,
86
                'мая' => 5,
87
                'чэр' => 6,
88
                'ліп' => 7,
89
                'жні' => 8,
90
                'вер' => 9,
91
                'кас' => 10,
92
                'ліс' => 11,
93
                'сне' => 12,
94
            ],
95
        ],
96
        'bg' => [
97
            'pattern' => '~^(?P<day>\d{1,2})\.(?P<month>\d{2})\.(?P<year>\d{4}) г.$~',
98
        ],
99
        'bn_BD' => [
100
            'pattern' => '~^(?P<day>\d+)\s(?P<month>.*?),\s(?P<year>\d{4})$~',
101
            'convert' => [__CLASS__, 'convertBengaliNumbers'],
102
            'months' => [
103
                'জানু' => 1,
104
                'ফেব' => 2,
105
                'মার্চ' => 3,
106
                'এপ্রিল' => 4,
107
                'মে' => 5,
108
                'জুন' => 6,
109
                'জুলাই' => 7,
110
                'আগস্ট' => 8,
111
                'সেপ্টেম্বর' => 9,
112
                'অক্টোবর' => 10,
113
                'নভেম্বর' => 11,
114
                'ডিসেম্বর' => 12,
115
            ],
116
        ],
117
        'ca' => [
118
            'pattern' => '~^(?P<day>\d{1,2})\s(?P<month>.*)\s(?P<year>\d{4})$~',
119
            'months' => [
120
                'de gen.' => 1,
121
                'de febr.' => 2,
122
                'de març' => 3,
123
                'd’abr.' => 4,
124
                'de maig' => 5,
125
                'de juny' => 6,
126
                'de jul.' => 7,
127
                'd’ag.' => 8,
128
                'de set.' => 9,
129
                'd’oct.' => 10,
130
                'de nov.' => 11,
131
                'de des.' => 12,
132
            ],
133
        ],
134
        'cs_CZ' => [
135
            'pattern' => '~^(?P<day>\d{1,2})\.\s(?P<month>\d{1,2})\.\s(?P<year>\d{4})$~',
136
        ],
137
        'da_DK' => [
138
            'pattern' => '~^(?P<day>\d{1,2})\.\s(?P<month>.*?)\s(?P<year>\d{4})$~',
139
            'months' => [
140
                'jan.' => 1,
141
                'feb.' => 2,
142
                'mar.' => 3,
143
                'apr.' => 4,
144
                'maj' => 5,
145
                'jun.' => 6,
146
                'jul.' => 7,
147
                'aug.' => 8,
148
                'sep.' => 9,
149
                'okt.' => 10,
150
                'nov.' => 11,
151
                'dec.' => 12,
152
            ],
153
        ],
154
        'de_DE' => [
155
            'pattern' => '~^(?P<day>\d{2})\.(?P<month>\d{2})\.(?P<year>\d{4})$~',
156
        ],
157
        'el_GR' => [
158
            'pattern' => '~^(?P<day>\d{1,2})\s(?P<month>.*?)\s(?P<year>\d{4})$~',
159
            'months' => [
160
                'Ιαν' => 1,
161
                'Φεβ' => 2,
162
                'Μαρ' => 3,
163
                'Απρ' => 4,
164
                'Μαΐ' => 5,
165
                'Ιουν' => 6,
166
                'Ιουλ' => 7,
167
                'Αυγ' => 8,
168
                'Σεπ' => 9,
169
                'Οκτ' => 10,
170
                'Νοε' => 11,
171
                'Δεκ' => 12,
172
            ],
173
        ],
174
        'en_AU' => [
175
            'pattern' => '~^(?P<day>\d{1,2})\s(?P<month>.*?)\s(?P<year>\d{4})$~',
176
            'months' => [
177
                'Jan' => 1,
178
                'Feb' => 2,
179
                'Mar' => 3,
180
                'Apr' => 4,
181
                'May' => 5,
182
                'Jun' => 6,
183
                'June' => 6,
184
                'Jul' => 7,
185
                'July' => 7,
186
                'Aug' => 8,
187
                'Sep' => 9,
188
                'Sept' => 9,
189
                'Oct' => 10,
190
                'Nov' => 11,
191
                'Dec' => 12,
192
            ],
193
        ],
194
        'en_CA' => [
195
            'pattern' => '~^(?P<month>.*?)\.?\s(?P<day>\d{1,2}),\s(?P<year>\d{4})$~',
196
            'months' => [
197
                'Jan' => 1,
198
                'Feb' => 2,
199
                'Mar' => 3,
200
                'Apr' => 4,
201
                'May' => 5,
202
                'Jun' => 6,
203
                'Jul' => 7,
204
                'Aug' => 8,
205
                'Sep' => 9,
206
                'Sept' => 9,
207
                'Oct' => 10,
208
                'Nov' => 11,
209
                'Dec' => 12,
210
            ],
211
        ],
212
        'en_GB' => [
213
            'pattern' => '~^(?P<day>\d{1,2})\s(?P<month>.*?)\s(?P<year>\d{4})$~',
214
            'months' => [
215
                'Jan' => 1,
216
                'Feb' => 2,
217
                'Mar' => 3,
218
                'Apr' => 4,
219
                'May' => 5,
220
                'Jun' => 6,
221
                'June' => 6,
222
                'Jul' => 7,
223
                'July' => 7,
224
                'Aug' => 8,
225
                'Sep' => 9,
226
                'Sept' => 9,
227
                'Oct' => 10,
228
                'Nov' => 11,
229
                'Dec' => 12,
230
            ],
231
        ],
232
        'en_IN' => [
233
            'pattern' => '~^(?P<day>\d{1,2})-(?P<month>.*?)-(?P<year>\d{4})$~',
234
            'months' => [
235
                'Jan' => 1,
236
                'Feb' => 2,
237
                'Mar' => 3,
238
                'Apr' => 4,
239
                'May' => 5,
240
                'Jun' => 6,
241
                'Jul' => 7,
242
                'Aug' => 8,
243
                'Sep' => 9,
244
                'Sept' => 9,
245
                'Oct' => 10,
246
                'Nov' => 11,
247
                'Dec' => 12,
248
            ],
249
        ],
250
        'en_SG' => [
251
            'pattern' => '~^(?P<day>\d{1,2})\s(?P<month>.*?)\s(?P<year>\d{4})$~',
252
            'months' => [
253
                'Jan' => 1,
254
                'Feb' => 2,
255
                'Mar' => 3,
256
                'Apr' => 4,
257
                'May' => 5,
258
                'Jun' => 6,
259
                'Jul' => 7,
260
                'Aug' => 8,
261
                'Sep' => 9,
262
                'Sept' => 9,
263
                'Oct' => 10,
264
                'Nov' => 11,
265
                'Dec' => 12,
266
            ],
267
        ],
268
        'en_US' => [
269
            'pattern' => '~^(?P<month>.*?)\s(?P<day>\d{1,2}),\s(?P<year>\d{4})$~',
270
            'months' => [
271
                'Jan' => 1,
272
                'Feb' => 2,
273
                'Mar' => 3,
274
                'Apr' => 4,
275
                'May' => 5,
276
                'Jun' => 6,
277
                'Jul' => 7,
278
                'Aug' => 8,
279
                'Sep' => 9,
280
                'Oct' => 10,
281
                'Nov' => 11,
282
                'Dec' => 12,
283
            ],
284
        ],
285
        'en_ZA' => [
286
            'pattern' => '~^(?P<day>\d{2})\s(?P<month>.*?)\s(?P<year>\d{4})$~',
287
            'months' => [
288
                'Jan' => 1,
289
                'Feb' => 2,
290
                'Mar' => 3,
291
                'Apr' => 4,
292
                'May' => 5,
293
                'Jun' => 6,
294
                'Jul' => 7,
295
                'Aug' => 8,
296
                'Sep' => 9,
297
                'Sept' => 9,
298
                'Oct' => 10,
299
                'Nov' => 11,
300
                'Dec' => 12,
301
            ],
302
        ],
303
        'es_419' => [
304
            'pattern' => '~^(?P<day>\d{1,2})\s(?P<month>.*?)\.?\s(?P<year>\d{4})$~',
305
            'months' => [
306
                'ene' => 1,
307
                'feb' => 2,
308
                'mar' => 3,
309
                'abr' => 4,
310
                'may' => 5,
311
                'jun' => 6,
312
                'jul' => 7,
313
                'ago' => 8,
314
                'sep' => 9,
315
                'sept' => 9,
316
                'oct' => 10,
317
                'nov' => 11,
318
                'dic' => 12,
319
            ],
320
        ],
321
        'es_ES' => [
322
            'pattern' => '~^(?P<day>\d{1,2})\s(?P<month>.*?)\.?\s(?P<year>\d{4})$~',
323
            'months' => [
324
                'ene' => 1,
325
                'feb' => 2,
326
                'mar' => 3,
327
                'abr' => 4,
328
                'may' => 5,
329
                'jun' => 6,
330
                'jul' => 7,
331
                'ago' => 8,
332
                'sept' => 9,
333
                'oct' => 10,
334
                'nov' => 11,
335
                'dic' => 12,
336
            ],
337
        ],
338
        'es_US' => [
339
            'pattern' => '~^(?P<day>\d{1,2})\s(?P<month>.*?)\.?\s(?P<year>\d{4})$~',
340
            'months' => [
341
                'ene' => 1,
342
                'feb' => 2,
343
                'mar' => 3,
344
                'abr' => 4,
345
                'may' => 5,
346
                'jun' => 6,
347
                'jul' => 7,
348
                'ago' => 8,
349
                'sep' => 9,
350
                'sept' => 9,
351
                'oct' => 10,
352
                'nov' => 11,
353
                'dic' => 12,
354
            ],
355
        ],
356
        'et' => [
357
            'pattern' => '~^(?P<day>\d{1,2})\.\s(?P<month>.*?)\s(?P<year>\d{4})$~',
358
            'months' => [
359
                'jaan' => 1,
360
                'veebr' => 2,
361
                'märts' => 3,
362
                'apr' => 4,
363
                'mai' => 5,
364
                'juuni' => 6,
365
                'juuli' => 7,
366
                'aug' => 8,
367
                'sept' => 9,
368
                'okt' => 10,
369
                'nov' => 11,
370
                'dets' => 12,
371
            ],
372
        ],
373
        'eu_ES' => [
374
            'pattern' => '~^(?P<year>\d{4})\(e\)ko (?P<month>.*?)\.\s(?P<day>\d{1,2})\(a\)$~',
375
            'months' => [
376
                'urt' => 1,
377
                'ots' => 2,
378
                'mar' => 3,
379
                'api' => 4,
380
                'mai' => 5,
381
                'eka' => 6,
382
                'uzt' => 7,
383
                'abu' => 8,
384
                'ira' => 9,
385
                'urr' => 10,
386
                'aza' => 11,
387
                'abe' => 12,
388
            ],
389
        ],
390
        'fa' => [
391
            'pattern' => '~^(?P<day>\d+)\s(?P<month>.*?)\s(?P<year>\d{4})$~',
392
            'convert' => [__CLASS__, 'convertFarsiNumbers'],
393
            'convertCalendar' => [__CLASS__, 'convertPersianToGregorianCalendar'],
394
            'months' => [
395
                'فروردین' => 1,
396
                'اردیبهشت' => 2,
397
                'خرداد' => 3,
398
                'تیر' => 4,
399
                'مرداد' => 5,
400
                'شهریور' => 6,
401
                'مهر' => 7,
402
                'آبان' => 8,
403
                'آذر' => 9,
404
                'دی' => 10,
405
                'بهمن' => 11,
406
                'اسفند' => 12,
407
            ],
408
        ],
409
        'fi_FI' => [
410
            'pattern' => '~^(?P<day>\d{1,2})\.(?P<month>\d{1,2})\.(?P<year>\d{4})$~',
411
        ],
412
        'fil' => [
413
            'pattern' => '~^(?P<month>\w+)\s(?P<day>\d{1,2}),\s(?P<year>\d{4})$~',
414
            'months' => [
415
                'Ene' => 1,
416
                'Peb' => 2,
417
                'Mar' => 3,
418
                'Abr' => 4,
419
                'May' => 5,
420
                'Hun' => 6,
421
                'Hul' => 7,
422
                'Ago' => 8,
423
                'Set' => 9,
424
                'Okt' => 10,
425
                'Nob' => 11,
426
                'Dis' => 12,
427
            ],
428
        ],
429
        'fr_CA' => [
430
            'pattern' => '~^(?P<day>\d{1,2})\s(?P<month>.*?)\s(?P<year>\d{4})$~',
431
            'months' => [
432
                'janv.' => 1,
433
                'févr.' => 2,
434
                'mars' => 3,
435
                'avr.' => 4,
436
                'mai' => 5,
437
                'juin' => 6,
438
                'juill.' => 7,
439
                'août' => 8,
440
                'sept.' => 9,
441
                'oct.' => 10,
442
                'nov.' => 11,
443
                'déc.' => 12,
444
            ],
445
        ],
446
        'fr_FR' => [
447
            'pattern' => '~^(?P<day>\d{1,2})\s(?P<month>.*?)\s(?P<year>\d{4})$~',
448
            'months' => [
449
                'janv.' => 1,
450
                'févr.' => 2,
451
                'mars' => 3,
452
                'avr.' => 4,
453
                'mai' => 5,
454
                'juin' => 6,
455
                'juil.' => 7,
456
                'août' => 8,
457
                'sept.' => 9,
458
                'oct.' => 10,
459
                'nov.' => 11,
460
                'déc.' => 12,
461
            ],
462
        ],
463
        'gl_ES' => [
464
            'pattern' => '~^(?P<day>\d{1,2})\sde\s(?P<month>.*?)\sde\s(?P<year>\d{4})$~',
465
            'months' => [
466
                'xan.' => 1,
467
                'feb.' => 2,
468
                'mar.' => 3,
469
                'abr.' => 4,
470
                'maio' => 5,
471
                'xuño' => 6,
472
                'xul.' => 7,
473
                'ago.' => 8,
474
                'set.' => 9,
475
                'out.' => 10,
476
                'nov.' => 11,
477
                'dec.' => 12,
478
            ],
479
        ],
480
        'hi_IN' => [
481
            'pattern' => '~^(?P<day>\d{1,2})\s(?P<month>.*?)\s(?P<year>\d{4})$~',
482
            'months' => [
483
                'जन॰' => 1,
484
                'फ़र॰' => 2,
485
                'मार्च' => 3,
486
                'अप्रैल' => 4,
487
                'मई' => 5,
488
                'जून' => 6,
489
                'जुल॰' => 7,
490
                'अग॰' => 8,
491
                'सित॰' => 9,
492
                'अक्तू॰' => 10,
493
                'नव॰' => 11,
494
                'दिस॰' => 12,
495
            ],
496
        ],
497
        'hr' => [
498
            'pattern' => '~^(?P<day>\d{1,2})\.\s(?P<month>.*?)\s(?P<year>\d{4})\.$~',
499
            'months' => [
500
                'sij' => 1,
501
                'velj' => 2,
502
                'ožu' => 3,
503
                'tra' => 4,
504
                'svi' => 5,
505
                'lip' => 6,
506
                'srp' => 7,
507
                'kol' => 8,
508
                'ruj' => 9,
509
                'lis' => 10,
510
                'stu' => 11,
511
                'pro' => 12,
512
            ],
513
        ],
514
        'hu_HU' => [
515
            'pattern' => '~^(?P<year>\d{4})\.\s(?P<month>.*?)\.\s(?P<day>\d{1,2})\.$~',
516
            'months' => [
517
                'jan' => 1,
518
                'febr' => 2,
519
                'márc' => 3,
520
                'ápr' => 4,
521
                'máj' => 5,
522
                'jún' => 6,
523
                'júl' => 7,
524
                'aug' => 8,
525
                'szept' => 9,
526
                'okt' => 10,
527
                'nov' => 11,
528
                'dec' => 12,
529
            ],
530
        ],
531
        'hy_AM' => [
532
            'pattern' => '~^(?P<day>\d{2})\s(?P<month>.*?),\s(?P<year>\d{4})\sթ.$~',
533
            'months' => [
534
                'հնվ' => 1,
535
                'փտվ' => 2,
536
                'մրտ' => 3,
537
                'ապր' => 4,
538
                'մյս' => 5,
539
                'հնս' => 6,
540
                'հլս' => 7,
541
                'օգս' => 8,
542
                'սեպ' => 9,
543
                'հոկ' => 10,
544
                'նոյ' => 11,
545
                'դեկ' => 12,
546
            ],
547
        ],
548
        'id' => [
549
            'pattern' => '~^(?P<day>\d{1,2})\s(?P<month>.*?)\s(?P<year>\d{4})$~',
550
            'months' => [
551
                'Jan' => 1,
552
                'Feb' => 2,
553
                'Mar' => 3,
554
                'Apr' => 4,
555
                'Mei' => 5,
556
                'Jun' => 6,
557
                'Jul' => 7,
558
                'Agu' => 8,
559
                'Sep' => 9,
560
                'Okt' => 10,
561
                'Nov' => 11,
562
                'Des' => 12,
563
            ],
564
        ],
565
        'is_IS' => [
566
            'pattern' => '~^(?P<day>\d{1,2})\.\s(?P<month>.*?)\s(?P<year>\d{4})$~',
567
            'months' => [
568
                'jan.' => 1,
569
                'feb.' => 2,
570
                'mar.' => 3,
571
                'apr.' => 4,
572
                'maí' => 5,
573
                'jún.' => 6,
574
                'júl.' => 7,
575
                'ágú.' => 8,
576
                'sep.' => 9,
577
                'okt.' => 10,
578
                'nóv.' => 11,
579
                'des.' => 12,
580
            ],
581
        ],
582
        'it_IT' => [
583
            'pattern' => '~^(?P<day>\d{1,2})\s(?P<month>.*?)\s(?P<year>\d{4})$~',
584
            'months' => [
585
                'gen' => 1,
586
                'feb' => 2,
587
                'mar' => 3,
588
                'apr' => 4,
589
                'mag' => 5,
590
                'giu' => 6,
591
                'lug' => 7,
592
                'ago' => 8,
593
                'set' => 9,
594
                'ott' => 10,
595
                'nov' => 11,
596
                'dic' => 12,
597
            ],
598
        ],
599
        'iw_IL' => [
600
            'pattern' => '~^(?P<day>\d{1,2})\s(?P<month>.*?)\s(?P<year>\d{4})$~',
601
            'months' => [
602
                'בינו׳' => 1,
603
                'בפבר׳' => 2,
604
                'במרץ' => 3,
605
                'באפר׳' => 4,
606
                'במאי' => 5,
607
                'ביוני' => 6,
608
                'ביולי' => 7,
609
                'באוג׳' => 8,
610
                'בספט׳' => 9,
611
                'באוק׳' => 10,
612
                'בנוב׳' => 11,
613
                'בדצמ׳' => 12,
614
            ],
615
        ],
616
        'ja_JP' => [
617
            'pattern' => '~^(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d{2})$~',
618
        ],
619
        'ka_GE' => [
620
            'pattern' => '~^(?P<day>\d{1,2})\s(?P<month>.*?)\.\s(?P<year>\d{4})$~',
621
            'months' => [
622
                'იან' => 1,
623
                'თებ' => 2,
624
                'მარ' => 3,
625
                'აპრ' => 4,
626
                'მაი' => 5,
627
                'ივნ' => 6,
628
                'ივლ' => 7,
629
                'აგვ' => 8,
630
                'სექ' => 9,
631
                'ოქტ' => 10,
632
                'ნოე' => 11,
633
                'დეკ' => 12,
634
            ],
635
        ],
636
        'kk' => [
637
            'pattern' => '~^(?P<year>\d{4})\sж\.\s(?P<day>\d{2})\s(?P<month>.*?)$~',
638
            'months' => [
639
                'қаң.' => 1,
640
                'ақп.' => 2,
641
                'нау.' => 3,
642
                'сәу.' => 4,
643
                'мам.' => 5,
644
                'мау.' => 6,
645
                'шіл.' => 7,
646
                'там.' => 8,
647
                'қыр.' => 9,
648
                'қаз.' => 10,
649
                'қар.' => 11,
650
                'жел.' => 12,
651
            ],
652
        ],
653
        'km_KH' => [
654
            'pattern' => '~^(?P<day>\d{1,2})\s(?P<month>.*?)\s(?P<year>\d{4})$~',
655
            'months' => [
656
                'មករា' => 1,
657
                'កុម្ភៈ' => 2,
658
                'មីនា' => 3,
659
                'មេសា' => 4,
660
                'ឧសភា' => 5,
661
                'មិថុនា' => 6,
662
                'កក្កដា' => 7,
663
                'សីហា' => 8,
664
                'កញ្ញា' => 9,
665
                'តុលា' => 10,
666
                'វិច្ឆិកា' => 11,
667
                'ធ្នូ' => 12,
668
            ],
669
        ],
670
        'kn_IN' => [
671
            'pattern' => '~^(?P<month>.*?)\s(?P<day>\d{1,2}),\s(?P<year>\d{4})$~',
672
            'months' => [
673
                'ಜನವರಿ' => 1,
674
                'ಫೆಬ್ರವರಿ' => 2,
675
                'ಮಾರ್ಚ್' => 3,
676
                'ಏಪ್ರಿ' => 4,
677
                'ಮೇ' => 5,
678
                'ಜೂನ್' => 6,
679
                'ಜುಲೈ' => 7,
680
                'ಆಗ' => 8,
681
                'ಸೆಪ್ಟೆಂ' => 9,
682
                'ಅಕ್ಟೋ' => 10,
683
                'ನವೆಂ' => 11,
684
                'ಡಿಸೆಂ' => 12,
685
            ],
686
        ],
687
        'ko_KR' => [
688
            'pattern' => '~^(?P<year>\d{4})\.\s(?P<month>\d{1,2})\.\s(?P<day>\d{1,2})\.$~',
689
        ],
690
        'ky_KG' => [
691
            'pattern' => '~^(?P<year>\d{4})-ж\.,\s(?P<day>\d{1,2})-(?P<month>.*?)$~',
692
            'months' => [
693
                'янв.' => 1,
694
                'фев.' => 2,
695
                'мар.' => 3,
696
                'апр.' => 4,
697
                'май' => 5,
698
                'июн.' => 6,
699
                'июл.' => 7,
700
                'авг.' => 8,
701
                'сен.' => 9,
702
                'окт.' => 10,
703
                'ноя.' => 11,
704
                'дек.' => 12,
705
            ],
706
        ],
707
        'lo_LA' => [
708
            'pattern' => '~^(?P<day>\d{1,2})\s(?P<month>.*?)\s(?P<year>\d{4})$~',
709
            'months' => [
710
                'ມ.ກ.' => 1,
711
                'ກ.ພ.' => 2,
712
                'ມ.ນ.' => 3,
713
                'ມ.ສ.' => 4,
714
                'ພ.ພ.' => 5,
715
                'ມິ.ຖ.' => 6,
716
                'ກ.ລ.' => 7,
717
                'ສ.ຫ.' => 8,
718
                'ກ.ຍ.' => 9,
719
                'ຕ.ລ.' => 10,
720
                'ພ.ຈ.' => 11,
721
                'ທ.ວ.' => 12,
722
            ],
723
        ],
724
        'lt' => [
725
            'pattern' => '~^(?P<year>\d{4})-(?P<month>\d{2})-(?P<day>\d{2})$~',
726
        ],
727
        'lv' => [
728
            'pattern' => '~^(?P<year>\d{4})\.\sgada\s(?P<day>\d{1,2})\.\s(?P<month>.*?)$~',
729
            'months' => [
730
                'janv.' => 1,
731
                'febr.' => 2,
732
                'marts' => 3,
733
                'apr.' => 4,
734
                'maijs' => 5,
735
                'jūn.' => 6,
736
                'jūl.' => 7,
737
                'aug.' => 8,
738
                'sept.' => 9,
739
                'okt.' => 10,
740
                'nov.' => 11,
741
                'dec.' => 12,
742
            ],
743
        ],
744
        'mk_MK' => [
745
            'pattern' => '~^(?P<day>\d{1,2})\.(?P<month>\d{1,2})\.(?P<year>\d{4})$~',
746
        ],
747
        'ml_IN' => [
748
            'pattern' => '~^(?P<year>\d{4}),\s(?P<month>.*?)\s(?P<day>\d{1,2})$~',
749
            'months' => [
750
                'ജനു' => 1,
751
                'ഫെബ്രു' => 2,
752
                'മാർ' => 3,
753
                'ഏപ്രി' => 4,
754
                'മേയ്' => 5,
755
                'ജൂൺ' => 6,
756
                'ജൂലൈ' => 7,
757
                'ഓഗ' => 8,
758
                'സെപ്റ്റം' => 9,
759
                'ഒക്ടോ' => 10,
760
                'നവം' => 11,
761
                'ഡിസം' => 12,
762
            ],
763
        ],
764
        'mn_MN' => [
765
            'pattern' => '~^(?P<year>\d{4})\sоны\s(?P<month>\d{1,2})-р\sсарын\s(?P<day>\d{1,2})$~',
766
        ],
767
        'mr_IN' => [
768
            'pattern' => '~^(?P<day>\d{1,2})\s(?P<month>.*?),\s(?P<year>\d{4})$~',
769
            'convert' => [__CLASS__, 'convertMarathiNumbers'],
770
            'months' => [
771
                'जाने' => 1,
772
                'फेब्रु' => 2,
773
                'मार्च' => 3,
774
                'एप्रि' => 4,
775
                'मे' => 5,
776
                'जून' => 6,
777
                'जुलै' => 7,
778
                'ऑग' => 8,
779
                'सप्टें' => 9,
780
                'ऑक्टो' => 10,
781
                'नोव्हें' => 11,
782
                'डिसें' => 12,
783
            ],
784
        ],
785
        'ms' => [
786
            'pattern' => '~^(?P<day>\d{1,2})\s(?P<month>.*?)\s(?P<year>\d{4})$~',
787
            'months' => [
788
                'Jan' => 1,
789
                'Feb' => 2,
790
                'Mac' => 3,
791
                'Apr' => 4,
792
                'Mei' => 5,
793
                'Jun' => 6,
794
                'Jul' => 7,
795
                'Ogo' => 8,
796
                'Sep' => 9,
797
                'Okt' => 10,
798
                'Nov' => 11,
799
                'Dis' => 12,
800
            ],
801
        ],
802
        'my_MM' => [
803
            'pattern' => '~^(?P<year>\d{4})-\s(?P<month>.*?)\s(?P<day>\d{1,2})$~',
804
            'convert' => [__CLASS__, 'convertBurmeseNumbers'],
805
            'months' => [
806
                'ဇန်' => 1,
807
                'ဖေ' => 2,
808
                'မတ်' => 3,
809
                'ဧ' => 4,
810
                'မေ' => 5,
811
                'ဇွန်' => 6,
812
                'ဇူ' => 7,
813
                'ဩ' => 8,
814
                'စက်' => 9,
815
                'အောက်' => 10,
816
                'နို' => 11,
817
                'ဒီ' => 12,
818
            ],
819
        ],
820
        'ne_NP' => [
821
            'pattern' => '~^(?P<year>\d{4})\s(?P<month>.*?)\s(?P<day>\d{1,2})$~',
822
            'convert' => [__CLASS__, 'convertNepalNumbers'],
823
            'months' => [
824
                'जनवरी' => 1,
825
                'फेब्रुअरी' => 2,
826
                'मार्च' => 3,
827
                'अप्रिल' => 4,
828
                'मे' => 5,
829
                'जुन' => 6,
830
                'जुलाई' => 7,
831
                'अगस्ट' => 8,
832
                'सेप्टेम्बर' => 9,
833
                'अक्टोबर' => 10,
834
                'नोभेम्बर' => 11,
835
                'डिसेम्बर' => 12,
836
            ],
837
        ],
838
        'nl_NL' => [
839
            'pattern' => '~^(?P<day>\d{1,2})\s(?P<month>.*?)\s(?P<year>\d{4})$~',
840
            'months' => [
841
                'jan.' => 1,
842
                'feb.' => 2,
843
                'mrt.' => 3,
844
                'apr.' => 4,
845
                'mei' => 5,
846
                'jun.' => 6,
847
                'jul.' => 7,
848
                'aug.' => 8,
849
                'sep.' => 9,
850
                'okt.' => 10,
851
                'nov.' => 11,
852
                'dec.' => 12,
853
            ],
854
        ],
855
        'no_NO' => [
856
            'pattern' => '~^(?P<day>\d{1,2})\.\s(?P<month>.*?)\s(?P<year>\d{4})$~',
857
            'months' => [
858
                'jan.' => 1,
859
                'feb.' => 2,
860
                'mar.' => 3,
861
                'apr.' => 4,
862
                'mai' => 5,
863
                'jun.' => 6,
864
                'jul.' => 7,
865
                'aug.' => 8,
866
                'sep.' => 9,
867
                'okt.' => 10,
868
                'nov.' => 11,
869
                'des.' => 12,
870
            ],
871
        ],
872
        'pl_PL' => [
873
            'pattern' => '~^(?P<day>\d{1,2})\s(?P<month>.*?)\s(?P<year>\d{4})$~',
874
            'months' => [
875
                'sty' => 1,
876
                'lut' => 2,
877
                'mar' => 3,
878
                'kwi' => 4,
879
                'maj' => 5,
880
                'cze' => 6,
881
                'lip' => 7,
882
                'sie' => 8,
883
                'wrz' => 9,
884
                'paź' => 10,
885
                'lis' => 11,
886
                'gru' => 12,
887
            ],
888
        ],
889
        'pt_BR' => [
890
            'pattern' => '~^(?P<day>\d{1,2})\sde\s(?P<month>.*?)\.\sde\s(?P<year>\d{4})$~',
891
            'months' => [
892
                'jan' => 1,
893
                'fev' => 2,
894
                'mar' => 3,
895
                'abr' => 4,
896
                'mai' => 5,
897
                'jun' => 6,
898
                'jul' => 7,
899
                'ago' => 8,
900
                'set' => 9,
901
                'out' => 10,
902
                'nov' => 11,
903
                'dez' => 12,
904
            ],
905
        ],
906
        'pt_PT' => [
907
            'pattern' => '~^(?P<day>\d{2})/(?P<month>\d{2})/(?P<year>\d{4})$~',
908
        ],
909
        'ro' => [
910
            'pattern' => '~^(?P<day>\d{1,2})\s(?P<month>.*?)\s(?P<year>\d{4})$~',
911
            'months' => [
912
                'ian.' => 1,
913
                'feb.' => 2,
914
                'mar.' => 3,
915
                'apr.' => 4,
916
                'mai' => 5,
917
                'iun.' => 6,
918
                'iul.' => 7,
919
                'aug.' => 8,
920
                'sept.' => 9,
921
                'oct.' => 10,
922
                'nov.' => 11,
923
                'dec.' => 12,
924
            ],
925
        ],
926
        'ru_RU' => [
927
            'pattern' => '~^(?P<day>\d{1,2})\s(?P<month>.*?)\s(?P<year>\d{4})\sг\.$~',
928
            'months' => [
929
                'янв.' => 1,
930
                'февр.' => 2,
931
                'мар.' => 3,
932
                'апр.' => 4,
933
                'мая' => 5,
934
                'июн.' => 6,
935
                'июл.' => 7,
936
                'авг.' => 8,
937
                'сент.' => 9,
938
                'окт.' => 10,
939
                'нояб.' => 11,
940
                'дек.' => 12,
941
            ],
942
        ],
943
        'si_LK' => [
944
            'pattern' => '~^(?P<year>\d{4})\s(?P<month>.*?)\s(?P<day>\d{1,2})$~',
945
            'months' => [
946
                'ජන' => 1,
947
                'පෙබ' => 2,
948
                'මාර්තු' => 3,
949
                'අප්‍රේල්' => 4,
950
                'මැයි' => 5,
951
                'ජූනි' => 6,
952
                'ජූලි' => 7,
953
                'අගෝ' => 8,
954
                'සැප්' => 9,
955
                'ඔක්' => 10,
956
                'නොවැ' => 11,
957
                'දෙසැ' => 12,
958
            ],
959
        ],
960
        'sk' => [
961
            'pattern' => '~^(?P<day>\d{1,2})\.\s(?P<month>\d{1,2})\.\s(?P<year>\d{4})$~',
962
        ],
963
        'sl' => [
964
            'pattern' => '~^(?P<day>\d{1,2})\.\s(?P<month>.*?)\s(?P<year>\d{4})$~',
965
            'months' => [
966
                'jan.' => 1,
967
                'feb.' => 2,
968
                'mar.' => 3,
969
                'apr.' => 4,
970
                'maj' => 5,
971
                'jun.' => 6,
972
                'jul.' => 7,
973
                'avg.' => 8,
974
                'sep.' => 9,
975
                'okt.' => 10,
976
                'nov.' => 11,
977
                'dec.' => 12,
978
            ],
979
        ],
980
        'sr' => [
981
            'pattern' => '~^(?P<day>\d{1,2})\.\s(?P<month>\d{1,2})\.\s(?P<year>\d{4})\.$~',
982
        ],
983
        'sv_SE' => [
984
            'pattern' => '~^(?P<day>\d{1,2})\s(?P<month>.*?)\s(?P<year>\d{4})$~',
985
            'months' => [
986
                'jan.' => 1,
987
                'feb.' => 2,
988
                'mars' => 3,
989
                'apr.' => 4,
990
                'maj' => 5,
991
                'juni' => 6,
992
                'juli' => 7,
993
                'aug.' => 8,
994
                'sep.' => 9,
995
                'okt.' => 10,
996
                'nov.' => 11,
997
                'dec.' => 12,
998
            ],
999
        ],
1000
        'sw' => [
1001
            'pattern' => '~^(?P<day>\d{1,2})\s(?P<month>.*?)\s(?P<year>\d{4})$~',
1002
            'months' => [
1003
                'Jan' => 1,
1004
                'Feb' => 2,
1005
                'Mac' => 3,
1006
                'Apr' => 4,
1007
                'Mei' => 5,
1008
                'Jun' => 6,
1009
                'Jul' => 7,
1010
                'Ago' => 8,
1011
                'Sep' => 9,
1012
                'Okt' => 10,
1013
                'Nov' => 11,
1014
                'Des' => 12,
1015
            ],
1016
        ],
1017
        'ta_IN' => [
1018
            'pattern' => '~^(?P<day>\d{1,2})\s(?P<month>.*?),\s(?P<year>\d{4})$~',
1019
            'months' => [
1020
                'ஜன.' => 1,
1021
                'பிப்.' => 2,
1022
                'மார்.' => 3,
1023
                'ஏப்.' => 4,
1024
                'மே' => 5,
1025
                'ஜூன்' => 6,
1026
                'ஜூலை' => 7,
1027
                'ஆக.' => 8,
1028
                'செப்.' => 9,
1029
                'அக்.' => 10,
1030
                'நவ.' => 11,
1031
                'டிச.' => 12,
1032
            ],
1033
        ],
1034
        'te_IN' => [
1035
            'pattern' => '~^(?P<day>\d{1,2})\s(?P<month>.*?),\s(?P<year>\d{4})$~',
1036
            'months' => [
1037
                'జన' => 1,
1038
                'ఫిబ్ర' => 2,
1039
                'మార్చి' => 3,
1040
                'ఏప్రి' => 4,
1041
                'మే' => 5,
1042
                'జూన్' => 6,
1043
                'జులై' => 7,
1044
                'ఆగ' => 8,
1045
                'సెప్టెం' => 9,
1046
                'అక్టో' => 10,
1047
                'నవం' => 11,
1048
                'డిసెం' => 12,
1049
            ],
1050
        ],
1051
        'th' => [
1052
            'pattern' => '~^(?P<day>\d{1,2})\s(?P<month>.*?)\s(?P<year>\d{4})$~',
1053
            'convertCalendar' => [__CLASS__, 'convertThailandCalendar'],
1054
            'months' => [
1055
                'ม.ค.' => 1,
1056
                'ก.พ.' => 2,
1057
                'มี.ค.' => 3,
1058
                'เม.ย.' => 4,
1059
                'พ.ค.' => 5,
1060
                'มิ.ย.' => 6,
1061
                'ก.ค.' => 7,
1062
                'ส.ค.' => 8,
1063
                'ก.ย.' => 9,
1064
                'ต.ค.' => 10,
1065
                'พ.ย.' => 11,
1066
                'ธ.ค.' => 12,
1067
            ],
1068
        ],
1069
        'tr_TR' => [
1070
            'pattern' => '~^(?P<day>\d{1,2})\s(?P<month>.*?)\s(?P<year>\d{4})$~',
1071
            'months' => [
1072
                'Oca' => 1,
1073
                'Şub' => 2,
1074
                'Mar' => 3,
1075
                'Nis' => 4,
1076
                'May' => 5,
1077
                'Haz' => 6,
1078
                'Tem' => 7,
1079
                'Ağu' => 8,
1080
                'Eyl' => 9,
1081
                'Eki' => 10,
1082
                'Kas' => 11,
1083
                'Ara' => 12,
1084
            ],
1085
        ],
1086
        'uk' => [
1087
            'pattern' => '~^(?P<day>\d{1,2})\s(?P<month>.*?)\s(?P<year>\d{4})\sр\.$~',
1088
            'months' => [
1089
                'січ.' => 1,
1090
                'лют.' => 2,
1091
                'бер.' => 3,
1092
                'квіт.' => 4,
1093
                'трав.' => 5,
1094
                'черв.' => 6,
1095
                'лип.' => 7,
1096
                'серп.' => 8,
1097
                'вер.' => 9,
1098
                'жовт.' => 10,
1099
                'лист.' => 11,
1100
                'груд.' => 12,
1101
            ],
1102
        ],
1103
        'vi' => [
1104
            'pattern' => '~^(?P<day>\d{1,2})\s(?P<month>.*?),\s(?P<year>\d{4})$~',
1105
            'months' => [
1106
                'thg 1' => 1,
1107
                'thg 2' => 2,
1108
                'thg 3' => 3,
1109
                'thg 4' => 4,
1110
                'thg 5' => 5,
1111
                'thg 6' => 6,
1112
                'thg 7' => 7,
1113
                'thg 8' => 8,
1114
                'thg 9' => 9,
1115
                'thg 10' => 10,
1116
                'thg 11' => 11,
1117
                'thg 12' => 12,
1118
            ],
1119
        ],
1120
        'zh_CN' => [
1121
            'pattern' => '~^(?P<year>\d{4})年(?P<month>.*?)(?P<day>\d{1,2})日$~',
1122
            'months' => [
1123
                '1月' => 1,
1124
                '2月' => 2,
1125
                '3月' => 3,
1126
                '4月' => 4,
1127
                '5月' => 5,
1128
                '6月' => 6,
1129
                '7月' => 7,
1130
                '8月' => 8,
1131
                '9月' => 9,
1132
                '10月' => 10,
1133
                '11月' => 11,
1134
                '12月' => 12,
1135
            ],
1136
        ],
1137
        'zh_HK' => [
1138
            'pattern' => '~^(?P<year>\d{4})年(?P<month>.*?)(?P<day>\d{1,2})日$~',
1139
            'months' => [
1140
                '1月' => 1,
1141
                '2月' => 2,
1142
                '3月' => 3,
1143
                '4月' => 4,
1144
                '5月' => 5,
1145
                '6月' => 6,
1146
                '7月' => 7,
1147
                '8月' => 8,
1148
                '9月' => 9,
1149
                '10月' => 10,
1150
                '11月' => 11,
1151
                '12月' => 12,
1152
            ],
1153
        ],
1154
        'zh_TW' => [
1155
            'pattern' => '~^(?P<year>\d{4})年(?P<month>.*?)(?P<day>\d{1,2})日$~',
1156
            'months' => [
1157
                '1月' => 1,
1158
                '2月' => 2,
1159
                '3月' => 3,
1160
                '4月' => 4,
1161
                '5月' => 5,
1162
                '6月' => 6,
1163
                '7月' => 7,
1164
                '8月' => 8,
1165
                '9月' => 9,
1166
                '10月' => 10,
1167
                '11月' => 11,
1168
                '12月' => 12,
1169
            ],
1170
        ],
1171
        'zu' => [
1172
            'pattern' => '~^(?P<month>.*?)\s(?P<day>\d{1,2}),\s(?P<year>\d{4})$~',
1173
            'months' => [
1174
                'Jan' => 1,
1175
                'Feb' => 2,
1176
                'Mas' => 3,
1177
                'Eph' => 4,
1178
                'Mey' => 5,
1179
                'Jun' => 6,
1180
                'Jul' => 7,
1181
                'Aga' => 8,
1182
                'Sep' => 9,
1183
                'Okt' => 10,
1184
                'Nov' => 11,
1185
                'Dis' => 12,
1186
            ],
1187
        ],
1188
    ];
1189
1190
    /**
1191
     * Convert a date as localized string to a \DateTimeInterface object depending on locale.
1192
     *
1193
     * @param string $locale   locale
1194
     * @param string $dateText localized date
1195
     *
1196
     * @return \DateTimeInterface|null returns \DateTimeInterface or null if error
1197
     */
1198 954
    public static function formatted(string $locale, string $dateText): ?\DateTimeInterface
1199
    {
1200 954
        $locale = LocaleHelper::getNormalizeLocale($locale);
1201
1202 954
        if (!isset(self::MEDIUM_DATE_PATTERNS[$locale])) {
1203
            return null;
1204
        }
1205 954
        $datePatternObj = self::MEDIUM_DATE_PATTERNS[$locale];
1206
1207 954
        if (isset($datePatternObj['convert'])) {
1208 73
            $convertedText = forward_static_call($datePatternObj['convert'], $dateText);
1209 73
            if ($convertedText !== false){
1210 73
                $dateText = (string) $convertedText;
1211
            }
1212
        }
1213
1214 954
        if (preg_match($datePatternObj['pattern'], $dateText, $match)) {
1215 954
            $day = $match['day'];
1216 954
            $month = $match['month'];
1217 954
            $year = $match['year'];
1218
1219 954
            if (isset($datePatternObj['months'])) {
1220 798
                if (!isset($datePatternObj['months'][$month])) {
1221
                    throw new \RuntimeException(
1222
                        'Error convert date. Locale ' . $locale . '. Date: ' . $dateText .
1223
                        '. Matches: ' . var_export($match, true)
1224
                    );
1225
                }
1226 798
                $month = $datePatternObj['months'][$month];
1227
            }
1228
1229 954
            if (isset($datePatternObj['convertCalendar'])) {
1230 37
                [$year, $month, $day] = forward_static_call($datePatternObj['convertCalendar'], $year, $month, $day);
1231
            }
1232
1233 954
            $dateTime = \DateTimeImmutable::createFromFormat(
1234
                'Y.m.d H:i:s',
1235 954
                $year . '.' . $month . '.' . $day . ' 00:00:00',
1236 954
                new \DateTimeZone('UTC')
1237
            );
1238
1239 954
            if ($dateTime !== false) {
1240 954
                return $dateTime;
1241
            }
1242
        }
1243
1244
        return null;
1245
    }
1246
1247
    /**
1248
     * @param string|int $unixTime
1249
     *
1250
     * @return \DateTimeInterface|null
1251
     */
1252 20
    public static function unixTimeToDateTime($unixTime): ?\DateTimeInterface
1253
    {
1254 20
        $dateTime = \DateTimeImmutable::createFromFormat(
1255
            'U',
1256 20
            (string) $unixTime,
1257 20
            new \DateTimeZone('UTC')
1258
        );
1259
1260 20
        return $dateTime === false ? null : $dateTime;
1261
    }
1262
1263
    /**
1264
     * @param string $str
1265
     *
1266
     * @return string
1267
     */
1268 25
    private static function convertBengaliNumbers(string $str): string
1269
    {
1270 25
        return str_replace(
1271 25
            ['০', '১', '২', '৩', '৪', '৫', '৬', '৭', '৮', '৯'],
1272 25
            [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
1273
            $str
1274
        );
1275
    }
1276
1277
    /**
1278
     * @param string $str
1279
     *
1280
     * @return string
1281
     */
1282 25
    private static function convertFarsiNumbers(string $str): string
1283
    {
1284 25
        return str_replace(
1285 25
            ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹'],
1286 25
            [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
1287
            $str
1288
        );
1289
    }
1290
1291
    /**
1292
     * @param int $persianYear
1293
     * @param int $persianMonth
1294
     * @param int $persianDay
1295
     *
1296
     * @return array
1297
     */
1298 25
    private static function convertPersianToGregorianCalendar(
1299
        int $persianYear,
1300
        int $persianMonth,
1301
        int $persianDay
1302
    ): array {
1303
        $gregorianDaysInMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
1304
        $persianDaysInMonth = [31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29];
1305 25
        $jy = $persianYear - 979;
1306 25
        $jm = $persianMonth - 1;
1307 25
        $jd = $persianDay - 1;
1308 25
        $persianDayNo = 365 * $jy + floor($jy / 33) * 8 + floor(($jy % 33 + 3) / 4);
1309 25
        for ($i = 0; $i < $jm; ++$i) {
1310 25
            $persianDayNo += $persianDaysInMonth[$i];
1311
        }
1312 25
        $persianDayNo += $jd;
1313 25
        $gregorianDayNo = $persianDayNo + 79;
1314 25
        $gregorianYear = 1600 + 400 * floor($gregorianDayNo / 146097);
1315 25
        $gregorianDayNo %= 146097;
1316 25
        $leap = true;
1317
1318 25
        if ($gregorianDayNo >= 36525) {
1319
            $gregorianDayNo--;
1320
            $gregorianYear += 100 * floor($gregorianDayNo / 36524);
1321
            $gregorianDayNo %= 36524;
1322
1323
            if ($gregorianDayNo >= 365) {
1324
                $gregorianDayNo++;
1325
            } else {
1326
                $leap = false;
1327
            }
1328
        }
1329 25
        $gregorianYear += 4 * floor($gregorianDayNo / 1461);
1330 25
        $gregorianDayNo %= 1461;
1331
1332 25
        if ($gregorianDayNo >= 366) {
1333 21
            $leap = false;
1334 21
            $gregorianDayNo--;
1335 21
            $gregorianYear += floor($gregorianDayNo / 365);
1336 21
            $gregorianDayNo %= 365;
1337
        }
1338 25
        for ($i = 0; $gregorianDayNo >= $gregorianDaysInMonth[$i] + ($i === 1 && $leap); $i++) {
1339 23
            $gregorianDayNo -= $gregorianDaysInMonth[$i] + ($i === 1 && $leap);
1340
        }
1341 25
        $gregorianMonth = $i + 1;
1342 25
        $gregorianDay = $gregorianDayNo + 1;
1343
1344 25
        return [$gregorianYear, $gregorianMonth, $gregorianDay];
1345
    }
1346
1347
    /**
1348
     * @param string $str
1349
     *
1350
     * @return string
1351
     */
1352 25
    private static function convertMarathiNumbers(string $str): string
1353
    {
1354 25
        return str_replace(
1355 25
            ['०', '१', '२', '३', '४', '५', '६', '७', '८', '९'],
1356 25
            [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
1357
            $str
1358
        );
1359
    }
1360
1361
    /**
1362
     * @param string $str
1363
     *
1364
     * @return string
1365
     */
1366 25
    private static function convertBurmeseNumbers(string $str): string
1367
    {
1368 25
        return str_replace(
1369 25
            ['၀', '၁', '၂', '၃', '၄', '၅', '၆', '၇', '၈', '၉'],
1370 25
            [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
1371
            $str
1372
        );
1373
    }
1374
1375
    /**
1376
     * @param string $str
1377
     *
1378
     * @return string
1379
     */
1380 25
    private static function convertNepalNumbers(string $str): string
1381
    {
1382 25
        return str_replace(
1383 25
            ['०', '१', '२', '३', '४', '५', '६', '७', '८', '९'],
1384 25
            [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
1385
            $str
1386
        );
1387
    }
1388
1389
    /**
1390
     * @param int $year
1391
     * @param int $month
1392
     * @param int $day
1393
     *
1394
     * @return array
1395
     */
1396 25
    private static function convertThailandCalendar(int $year, int $month, int $day): array
1397
    {
1398 25
        return [$year - 543, $month, $day];
1399
    }
1400
}
1401