Test Failed
Branch develop (c8bc8f)
by Alexey
08:48
created

DateStringFormatter   B

Complexity

Total Complexity 23

Size/Duplication

Total Lines 1321
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 23
lcom 0
cbo 1
dl 0
loc 1321
c 0
b 0
f 0
rs 8.8

9 Methods

Rating   Name   Duplication   Size   Complexity  
B formatted() 0 33 7
A unixTimeToDateTime() 0 9 2
A convertBengaliNumbers() 0 8 1
A convertFarsiNumbers() 0 8 1
B convertPersianToGregorianCalendar() 0 41 8
A convertMarathiNumbers() 0 8 1
A convertBurmeseNumbers() 0 8 1
A convertNepalNumbers() 0 8 1
A convertThailandCalendar() 0 4 1
1
<?php
2
/** @noinspection PhpUnusedPrivateMethodInspection */
3
declare(strict_types=1);
4
5
namespace Nelexa\GPlay\Util;
6
7
/**
8
 * The class for converting a localized date to the \DateTimeInterface.
9
 * It would be possible to use the php-intl library, but its different
10
 * versions give different results.
11
 *
12
 * @package Nelexa\GPlay\Util
13
 */
14
class DateStringFormatter
0 ignored issues
show
Coding Style introduced by
DateStringFormatter does not seem to conform to the naming convention (Utils?$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

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

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
1162
     */
1163
    public static function formatted(string $locale, string $dateText): ?\DateTimeInterface
1164
    {
1165
        $locale = LocaleHelper::getNormalizeLocale($locale);
0 ignored issues
show
Coding Style introduced by
Consider using a different name than the parameter $locale. This often makes code more readable.
Loading history...
1166
        if (!isset(self::MEDIUM_DATE_PATTERNS[$locale])) {
1167
            return null;
1168
        }
1169
        $datePatternObj = self::MEDIUM_DATE_PATTERNS[$locale];
1170
        if (isset($datePatternObj['convert'])) {
1171
            $dateText = forward_static_call($datePatternObj['convert'], $dateText);
0 ignored issues
show
Coding Style introduced by
Consider using a different name than the parameter $dateText. This often makes code more readable.
Loading history...
1172
        }
1173
        if (preg_match($datePatternObj['pattern'], $dateText, $match)) {
1174
            $day = $match['day'];
1175
            $month = $match['month'];
1176
            $year = $match['year'];
1177
            if (isset($datePatternObj['months'])) {
1178
                $month = $datePatternObj['months'][$month];
1179
            }
1180
1181
            if (isset($datePatternObj['convertCalendar'])) {
1182
                [$year, $month, $day] = forward_static_call($datePatternObj['convertCalendar'], $year, $month, $day);
1183
            }
1184
1185
            $dateTime = \DateTimeImmutable::createFromFormat(
1186
                'Y.m.d',
1187
                $year . '.' . $month . '.' . $day,
1188
                new \DateTimeZone('UTC')
1189
            );
1190
            if ($dateTime !== false) {
1191
                return $dateTime;
1192
            }
1193
        }
1194
        return null;
1195
    }
1196
1197
    /**
1198
     * @param string|int $unixTime
1199
     * @return \DateTimeInterface|null
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use \DateTimeImmutable.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
1200
     */
1201
    public static function unixTimeToDateTime($unixTime): ?\DateTimeInterface
1202
    {
1203
        $dateTime = \DateTimeImmutable::createFromFormat(
1204
            'U',
1205
            (string)$unixTime,
1206
            new \DateTimeZone('UTC')
1207
        );
1208
        return $dateTime === false ? null : $dateTime;
1209
    }
1210
1211
    /**
1212
     * @param string $str
1213
     * @return string
1214
     */
1215
    private static function convertBengaliNumbers(string $str): string
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
1216
    {
1217
        return str_replace(
1218
            ['০', '১', '২', '৩', '৪', '৫', '৬', '৭', '৮', '৯'],
1219
            [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
1220
            $str
1221
        );
1222
    }
1223
1224
    /**
1225
     * @param string $str
1226
     * @return string
1227
     */
1228
    private static function convertFarsiNumbers(string $str): string
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
1229
    {
1230
        return str_replace(
1231
            ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹'],
1232
            [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
1233
            $str
1234
        );
1235
    }
1236
1237
    /**
1238
     * @param int $persianYear
1239
     * @param int $persianMonth
1240
     * @param int $persianDay
1241
     * @return array
1242
     */
1243
    private static function convertPersianToGregorianCalendar(int $persianYear, int $persianMonth, int $persianDay): array
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
1244
    {
1245
        $gregorianDaysInMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
1246
        $persianDaysInMonth = [31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29];
1247
        $jy = $persianYear - 979;
1248
        $jm = $persianMonth - 1;
1249
        $jd = $persianDay - 1;
1250
        $persianDayNo = 365 * $jy + floor($jy / 33) * 8 + floor(($jy % 33 + 3) / 4);
1251
        for ($i = 0; $i < $jm; ++$i) {
1252
            $persianDayNo += $persianDaysInMonth[$i];
1253
        }
1254
        $persianDayNo += $jd;
1255
        $gregorianDayNo = $persianDayNo + 79;
1256
        $gregorianYear = 1600 + 400 * floor($gregorianDayNo / 146097);
1257
        $gregorianDayNo %= 146097;
1258
        $leap = true;
1259
        if ($gregorianDayNo >= 36525) {
1260
            $gregorianDayNo--;
1261
            $gregorianYear += 100 * floor($gregorianDayNo / 36524);
1262
            $gregorianDayNo %= 36524;
1263
            if ($gregorianDayNo >= 365) {
1264
                $gregorianDayNo++;
1265
            } else {
1266
                $leap = false;
1267
            }
1268
        }
1269
        $gregorianYear += 4 * floor($gregorianDayNo / 1461);
1270
        $gregorianDayNo %= 1461;
1271
        if ($gregorianDayNo >= 366) {
1272
            $leap = false;
1273
            $gregorianDayNo--;
1274
            $gregorianYear += floor($gregorianDayNo / 365);
1275
            $gregorianDayNo %= 365;
1276
        }
1277
        for ($i = 0; $gregorianDayNo >= $gregorianDaysInMonth[$i] + ($i === 1 && $leap); $i++) {
1278
            $gregorianDayNo -= $gregorianDaysInMonth[$i] + ($i === 1 && $leap);
1279
        }
1280
        $gregorianMonth = $i + 1;
1281
        $gregorianDay = $gregorianDayNo + 1;
1282
        return [$gregorianYear, $gregorianMonth, $gregorianDay];
1283
    }
1284
1285
    /**
1286
     * @param string $str
1287
     * @return string
1288
     */
1289
    private static function convertMarathiNumbers(string $str): string
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
1290
    {
1291
        return str_replace(
1292
            ['०', '१', '२', '३', '४', '५', '६', '७', '८', '९'],
1293
            [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
1294
            $str
1295
        );
1296
    }
1297
1298
    /**
1299
     * @param string $str
1300
     * @return string
1301
     */
1302
    private static function convertBurmeseNumbers(string $str): string
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
1303
    {
1304
        return str_replace(
1305
            ['၀', '၁', '၂', '၃', '၄', '၅', '၆', '၇', '၈', '၉'],
1306
            [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
1307
            $str
1308
        );
1309
    }
1310
1311
    /**
1312
     * @param string $str
1313
     * @return string
1314
     */
1315
    private static function convertNepalNumbers(string $str): string
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
1316
    {
1317
        return str_replace(
1318
            ['०', '१', '२', '३', '४', '५', '६', '७', '८', '९'],
1319
            [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
1320
            $str
1321
        );
1322
    }
1323
1324
    /**
1325
     * @param int $year
1326
     * @param int $month
1327
     * @param int $day
1328
     * @return array
1329
     */
1330
    private static function convertThailandCalendar(int $year, int $month, int $day): array
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
1331
    {
1332
        return [$year - 543, $month, $day];
1333
    }
1334
}
1335