Passed
Push — master ( bb114b...6dc021 )
by Alexey
03:23 queued 10s
created

DateStringFormatter::convertBengaliNumbers()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

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