convertPersianToGregorianCalendar()   B
last analyzed

Complexity

Conditions 8
Paths 36

Size

Total Lines 47
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 27
CRAP Score 8.3844

Importance

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