Issues (1014)

Sources/Subs-Timezones.php (7 issues)

Labels
Severity
1
<?php
2
3
/**
4
 * This file provides some functions to simplify working with time zones.
5
 *
6
 * Simple Machines Forum (SMF)
7
 *
8
 * @package SMF
9
 * @author Simple Machines https://www.simplemachines.org
10
 * @copyright 2022 Simple Machines and individual contributors
11
 * @license https://www.simplemachines.org/about/smf/license.php BSD
12
 *
13
 * @version 2.1.2
14
 */
15
16
if (!defined('SMF'))
17
	die('No direct access...');
18
19
if (!defined('PHP_INT_MIN'))
20
	define('PHP_INT_MIN', ~PHP_INT_MAX);
21
22
/**
23
 * Returns an array that instructs SMF how to map specific time zones
24
 * (e.g. "America/Denver") onto the user-friendly "meta-zone" labels that
25
 * most people think of as time zones (e.g. "Mountain Time").
26
 *
27
 * @param string $when The date/time used to determine fallback values.
28
 *		May be a Unix timestamp or any string that strtotime() can understand.
29
 *		Defaults to 'now'.
30
 * @return array An array relating time zones to "meta-zones"
31
 */
32
function get_tzid_metazones($when = 'now')
33
{
34
	global $txt, $tztxt;
35
36
	// This should already have been loaded, but just in case...
37
	loadLanguage('Timezones');
38
39
	/*
40
		This array lists a series of representative time zones and their
41
		corresponding "meta-zone" labels.
42
43
		The term "representative" here means that a given time zone can
44
		represent others that use exactly the same rules for DST
45
		transitions, UTC offsets, and abbreviations. For example,
46
		Europe/Berlin can be representative for Europe/Rome,
47
		Europe/Paris, etc., because these cities all use exactly the
48
		same time zone rules and values.
49
50
		Meta-zone labels are the user friendly strings shown to the end
51
		user, e.g. "Mountain Standard Time". The values of this array
52
		are keys of strings defined in Timezones.{language}.php, which
53
		in turn are sprintf format strings used to generate the final
54
		label text.
55
56
		Sometimes several representative time zones will map onto the
57
		same meta-zone label. This usually happens when there are
58
		different rules for Daylight Saving time in locations that are
59
		otherwise the same. For example, both America/Denver and
60
		America/Phoenix map to North_America_Mountain, but the ultimate
61
		output will be 'Mountain Time (MST/MDT)' for America/Denver vs.
62
		'Mountain Standard Time (MST)' for America/Phoenix.
63
64
		If you are adding a new meta-zone to this list because the TZDB
65
		added a new time zone that doesn't fit any existing meta-zone,
66
		please also add a fallback in the get_tzid_fallbacks() function.
67
		This helps support SMF installs on servers using outdated
68
		versions of the TZDB.
69
	 */
70
	$tzid_metazones = array(
71
		// No DST
72
		'Africa/Abidjan' => 'GMT',
73
74
		// No DST
75
		'Africa/Algiers' => 'Europe_Central',
76
77
		// Uses DST
78
		'Africa/Casablanca' => 'Africa_Morocco',
79
80
		// No DST
81
		'Africa/Johannesburg' => 'Africa_South',
82
83
		// No DST
84
		'Africa/Lagos' => 'Africa_West',
85
86
		// No DST
87
		'Africa/Maputo' => 'Africa_Central',
88
89
		// No DST
90
		'Africa/Nairobi' => 'Africa_East',
91
92
		// Uses DST
93
		'America/Adak' => 'North_America_Hawaii_Aleutian',
94
95
		// Uses DST
96
		'America/Anchorage' => 'North_America_Alaska',
97
98
		// No DST
99
		'America/Argentina/Buenos_Aires' => 'South_America_Argentina',
100
101
		// Uses DST
102
		'America/Asuncion' => 'South_America_Paraguay',
103
104
		// No DST
105
		'America/Belize' => 'North_America_Central',
106
107
		// No DST
108
		'America/Bogota' => 'South_America_Colombia',
109
110
		// No DST
111
		'America/Caracas' => 'South_America_Venezuela',
112
113
		// No DST
114
		'America/Cayenne' => 'South_America_French_Guiana',
115
116
		// Uses DST
117
		'America/Chicago' => 'North_America_Central',
118
119
		// Uses DST
120
		'America/Chihuahua' => 'North_America_Mexico_Pacific',
121
122
		// Uses DST
123
		'America/Denver' => 'North_America_Mountain',
124
125
		// Uses DST
126
		'America/Nuuk' => 'North_America_Greenland_Western',
127
128
		// No DST
129
		'America/Guayaquil' => 'South_America_Ecuador',
130
131
		// No DST
132
		'America/Guyana' => 'South_America_Guyana',
133
134
		// Uses DST
135
		'America/Halifax' => 'North_America_Atlantic',
136
137
		// Uses DST
138
		'America/Havana' => 'North_America_Cuba',
139
140
		// No DST
141
		'America/Jamaica' => 'North_America_Eastern',
142
143
		// No DST
144
		'America/La_Paz' => 'South_America_Bolivia',
145
146
		// No DST
147
		'America/Lima' => 'South_America_Peru',
148
149
		// Uses DST
150
		'America/Los_Angeles' => 'North_America_Pacific',
151
152
		// No DST
153
		'America/Manaus' => 'South_America_Amazon',
154
155
		// Uses DST
156
		'America/Mexico_City' => 'North_America_Mexico_Central',
157
158
		// Uses DST
159
		'America/Miquelon' => 'North_America_St_Pierre_Miquelon',
160
161
		// No DST
162
		'America/Montevideo' => 'South_America_Uruguay',
163
164
		// Uses DST
165
		'America/New_York' => 'North_America_Eastern',
166
167
		// No DST
168
		'America/Noronha' => 'South_America_Noronha',
169
170
		// No DST
171
		'America/Paramaribo' => 'South_America_Suriname',
172
173
		// No DST
174
		'America/Phoenix' => 'North_America_Mountain',
175
176
		// No DST
177
		'America/Port_of_Spain' => 'North_America_Atlantic',
178
179
		// No DST
180
		'America/Punta_Arenas' => 'South_America_Chile_Magallanes',
181
182
		// No DST
183
		'America/Rio_Branco' => 'South_America_Acre',
184
185
		// Uses DST
186
		'America/Santiago' => 'South_America_Chile',
187
188
		// No DST
189
		'America/Sao_Paulo' => 'South_America_Brasilia',
190
191
		// Uses DST
192
		'America/Scoresbysund' => 'North_America_Greenland_Eastern',
193
194
		// Uses DST
195
		'America/St_Johns' => 'North_America_Newfoundland',
196
197
		// No DST
198
		'Antarctica/Casey' => 'Antarctica_Casey',
199
200
		// No DST
201
		'Antarctica/Davis' => 'Antarctica_Davis',
202
203
		// No DST
204
		'Antarctica/DumontDUrville' => 'Antarctica_DumontDUrville',
205
206
		// No DST
207
		'Antarctica/Macquarie' => 'Antarctica_Macquarie',
208
209
		// No DST
210
		'Antarctica/Mawson' => 'Antarctica_Mawson',
211
212
		// Uses DST
213
		'Antarctica/McMurdo' => 'Antarctica_McMurdo',
214
215
		// No DST
216
		'Antarctica/Palmer' => 'Antarctica_Palmer',
217
218
		// No DST
219
		'Antarctica/Rothera' => 'Antarctica_Rothera',
220
221
		// No DST
222
		'Antarctica/Syowa' => 'Antarctica_Syowa',
223
224
		// Uses DST
225
		'Antarctica/Troll' => 'Antarctica_Troll',
226
227
		// No DST
228
		'Antarctica/Vostok' => 'Antarctica_Vostok',
229
230
		// No DST
231
		'Asia/Almaty' => 'Asia_Kazakhstan_Eastern',
232
233
		// Uses DST
234
		'Asia/Amman' => 'Asia_Jordan',
235
236
		// No DST
237
		'Asia/Aqtau' => 'Asia_Kazakhstan_Western',
238
239
		// No DST
240
		'Asia/Ashgabat' => 'Asia_Turkmenistan',
241
242
		// No DST
243
		'Asia/Baku' => 'Asia_Azerbaijan',
244
245
		// No DST
246
		'Asia/Bangkok' => 'Asia_Southeast',
247
248
		// Uses DST
249
		'Asia/Beirut' => 'Asia_Libya',
250
251
		// No DST
252
		'Asia/Bishkek' => 'Asia_Kyrgystan',
253
254
		// No DST
255
		'Asia/Brunei' => 'Asia_Brunei',
256
257
		// Uses DST
258
		'Asia/Damascus' => 'Asia_Damascus',
259
260
		// No DST
261
		'Asia/Dhaka' => 'Asia_Bangladesh',
262
263
		// No DST
264
		'Asia/Dili' => 'Asia_East_Timor',
265
266
		// No DST
267
		'Asia/Dubai' => 'Asia_Gulf',
268
269
		// No DST
270
		'Asia/Dushanbe' => 'Asia_Tajikistan',
271
272
		// Uses DST
273
		'Asia/Gaza' => 'Asia_Palestine',
274
275
		// No DST
276
		'Asia/Hong_Kong' => 'Asia_Hong_Kong',
277
278
		// No DST
279
		'Asia/Hovd' => 'Asia_Mongolia_Western',
280
281
		// No DST
282
		'Asia/Irkutsk' => 'Asia_Irkutsk',
283
284
		// No DST
285
		'Asia/Jakarta' => 'Asia_Indonesia_Western',
286
287
		// No DST
288
		'Asia/Jayapura' => 'Asia_Indonesia_Eastern',
289
290
		// Uses DST
291
		'Asia/Jerusalem' => 'Asia_Israel',
292
293
		// No DST
294
		'Asia/Kabul' => 'Asia_Afghanistan',
295
296
		// No DST
297
		'Asia/Kamchatka' => 'Asia_Kamchatka',
298
299
		// No DST
300
		'Asia/Karachi' => 'Asia_Pakistan',
301
302
		// No DST
303
		'Asia/Kathmandu' => 'Asia_Nepal',
304
305
		// No DST
306
		'Asia/Kolkata' => 'Asia_India',
307
308
		// No DST
309
		'Asia/Krasnoyarsk' => 'Asia_Krasnoyarsk',
310
311
		// No DST
312
		'Asia/Kuala_Lumpur' => 'Asia_Malaysia',
313
314
		// No DST
315
		'Asia/Magadan' => 'Asia_Magadan',
316
317
		// No DST
318
		'Asia/Makassar' => 'Asia_Indonesia_Central',
319
320
		// No DST
321
		'Asia/Manila' => 'Asia_Philippines',
322
323
		// No DST
324
		'Asia/Omsk' => 'Asia_Omsk',
325
326
		// No DST
327
		'Asia/Riyadh' => 'Asia_Arabia',
328
329
		// No DST
330
		'Asia/Seoul' => 'Asia_Korea',
331
332
		// No DST
333
		'Asia/Shanghai' => 'Asia_China',
334
335
		// No DST
336
		'Asia/Singapore' => 'Asia_Singapore',
337
338
		// No DST
339
		'Asia/Taipei' => 'Asia_Taiwan',
340
341
		// No DST
342
		'Asia/Tashkent' => 'Asia_Uzbekistan',
343
344
		// No DST
345
		'Asia/Tbilisi' => 'Asia_Georgia',
346
347
		// Uses DST
348
		'Asia/Tehran' => 'Asia_Iran',
349
350
		// No DST
351
		'Asia/Thimphu' => 'Asia_Bhutan',
352
353
		// No DST
354
		'Asia/Tokyo' => 'Asia_Japan',
355
356
		// No DST
357
		'Asia/Ulaanbaatar' => 'Asia_Mongolia_Eastern',
358
359
		// No DST
360
		'Asia/Vladivostok' => 'Asia_Vladivostok',
361
362
		// No DST
363
		'Asia/Yakutsk' => 'Asia_Yakutsk',
364
365
		// No DST
366
		'Asia/Yangon' => 'Asia_Myanmar',
367
368
		// No DST
369
		'Asia/Yekaterinburg' => 'Asia_Yekaterinburg',
370
371
		// No DST
372
		'Asia/Yerevan' => 'Asia_Armenia',
373
374
		// Uses DST
375
		'Atlantic/Azores' => 'Atlantic_Azores',
376
377
		// No DST
378
		'Atlantic/Cape_Verde' => 'Atlantic_Cape_Verde',
379
380
		// No DST
381
		'Atlantic/South_Georgia' => 'Atlantic_South_Georgia',
382
383
		// No DST
384
		'Atlantic/Stanley' => 'Atlantic_Falkland',
385
386
		// Uses DST
387
		'Australia/Adelaide' => 'Australia_Central',
388
389
		// No DST
390
		'Australia/Brisbane' => 'Australia_Eastern',
391
392
		// No DST
393
		'Australia/Darwin' => 'Australia_Central',
394
395
		// No DST
396
		'Australia/Eucla' => 'Australia_CentralWestern',
397
398
		// Uses DST
399
		'Australia/Lord_Howe' => 'Australia_Lord_Howe',
400
401
		// Uses DST
402
		'Australia/Melbourne' => 'Australia_Eastern',
403
404
		// No DST
405
		'Australia/Perth' => 'Australia_Western',
406
407
		// Uses DST
408
		'Europe/Berlin' => 'Europe_Central',
409
410
		// Uses DST
411
		'Europe/Chisinau' => 'Europe_Moldova',
412
413
		// Uses DST
414
		'Europe/Dublin' => 'Europe_Eire',
415
416
		// Uses DST
417
		'Europe/Helsinki' => 'Europe_Eastern',
418
419
		// No DST
420
		'Europe/Istanbul' => 'Asia_Turkey',
421
422
		// No DST
423
		'Europe/Kaliningrad' => 'Europe_Eastern',
424
425
		// Uses DST
426
		'Europe/Lisbon' => 'Europe_Western',
427
428
		// Uses DST
429
		'Europe/London' => 'Europe_UK',
430
431
		// No DST
432
		'Europe/Minsk' => 'Europe_Minsk',
433
434
		// No DST
435
		'Europe/Moscow' => 'Europe_Moscow',
436
437
		// No DST
438
		'Europe/Samara' => 'Europe_Samara',
439
440
		// No DST
441
		'Europe/Volgograd' => 'Europe_Volgograd',
442
443
		// No DST
444
		'Indian/Chagos' => 'Indian_Chagos',
445
446
		// No DST
447
		'Indian/Christmas' => 'Indian_Christmas',
448
449
		// No DST
450
		'Indian/Cocos' => 'Indian_Cocos',
451
452
		// No DST
453
		'Indian/Kerguelen' => 'Indian_Kerguelen',
454
455
		// No DST
456
		'Indian/Mahe' => 'Indian_Seychelles',
457
458
		// No DST
459
		'Indian/Maldives' => 'Indian_Maldives',
460
461
		// No DST
462
		'Indian/Mauritius' => 'Indian_Mauritius',
463
464
		// No DST
465
		'Indian/Reunion' => 'Indian_Reunion',
466
467
		// Uses DST
468
		'Pacific/Apia' => 'Pacific_Apia',
469
470
		// Uses DST
471
		'Pacific/Auckland' => 'Pacific_New_Zealand',
472
473
		// No DST
474
		'Pacific/Bougainville' => 'Pacific_Bougainville',
475
476
		// Uses DST
477
		'Pacific/Chatham' => 'Pacific_Chatham',
478
479
		// No DST
480
		'Pacific/Chuuk' => 'Pacific_Chuuk',
481
482
		// Uses DST
483
		'Pacific/Easter' => 'Pacific_Easter',
484
485
		// No DST
486
		'Pacific/Efate' => 'Pacific_Vanuatu',
487
488
		// No DST
489
		'Pacific/Kanton' => 'Pacific_Phoenix_Islands',
490
491
		// No DST
492
		'Pacific/Fakaofo' => 'Pacific_Tokelau',
493
494
		// Uses DST
495
		'Pacific/Fiji' => 'Pacific_Fiji',
496
497
		// No DST
498
		'Pacific/Funafuti' => 'Pacific_Tuvalu',
499
500
		// No DST
501
		'Pacific/Galapagos' => 'Pacific_Galapagos',
502
503
		// No DST
504
		'Pacific/Gambier' => 'Pacific_Gambier',
505
506
		// No DST
507
		'Pacific/Guadalcanal' => 'Pacific_Solomon',
508
509
		// No DST
510
		'Pacific/Guam' => 'Pacific_Chamorro',
511
512
		// No DST
513
		'Pacific/Honolulu' => 'Pacific_Hawaii',
514
515
		// No DST
516
		'Pacific/Kiritimati' => 'Pacific_Line',
517
518
		// No DST
519
		'Pacific/Kwajalein' => 'Pacific_Marshall',
520
521
		// No DST
522
		'Pacific/Marquesas' => 'Pacific_Marquesas',
523
524
		// No DST
525
		'Pacific/Nauru' => 'Pacific_Nauru',
526
527
		// No DST
528
		'Pacific/Niue' => 'Pacific_Niue',
529
530
		// No DST
531
		'Pacific/Norfolk' => 'Pacific_Norfolk',
532
533
		// No DST
534
		'Pacific/Noumea' => 'Pacific_New_Caledonia',
535
536
		// No DST
537
		'Pacific/Pago_Pago' => 'Pacific_Samoa',
538
539
		// No DST
540
		'Pacific/Palau' => 'Pacific_Palau',
541
542
		// No DST
543
		'Pacific/Pitcairn' => 'Pacific_Pitcairn',
544
545
		// No DST
546
		'Pacific/Pohnpei' => 'Pacific_Pohnpei',
547
548
		// No DST
549
		'Pacific/Port_Moresby' => 'Pacific_Papua_New_Guinea',
550
551
		// No DST
552
		'Pacific/Rarotonga' => 'Pacific_Cook',
553
554
		// No DST
555
		'Pacific/Tahiti' => 'Pacific_Tahiti',
556
557
		// No DST
558
		'Pacific/Tarawa' => 'Pacific_Gilbert',
559
560
		// No DST
561
		'Pacific/Tongatapu' => 'Pacific_Tonga',
562
563
		// No DST
564
		'Pacific/Wake' => 'Pacific_Wake',
565
566
		// No DST
567
		'Pacific/Wallis' => 'Pacific_Wallis',
568
	);
569
570
	call_integration_hook('integrate_metazones', array(&$tzid_metazones, $when));
571
572
	// Fallbacks in case the server has an old version of the TZDB.
573
	$tzids = array_keys($tzid_metazones);
574
	$tzid_fallbacks = get_tzid_fallbacks($tzids, $when);
575
	foreach ($tzid_fallbacks as $orig_tzid => $alt_tzid)
576
	{
577
		// Skip any that are unchanged.
578
		if ($orig_tzid == $alt_tzid)
579
			continue;
580
581
		// Use fallback where possible.
582
		if (!empty($alt_tzid))
583
		{
584
			$tzid_metazones[$alt_tzid] = $tzid_metazones[$orig_tzid];
585
			$txt[$alt_tzid] = $txt[$orig_tzid];
586
		}
587
588
		// Either way, get rid of the unknown time zone.
589
		unset($tzid_metazones[$orig_tzid]);
590
	}
591
592
	return $tzid_metazones;
593
}
594
595
/**
596
 * Returns an array of all the time zones in a country, ranked according
597
 * to population and/or political significance.
598
 *
599
 * @param string $country_code The two-character ISO-3166 code for a country.
600
 * @param string $when The date/time used to determine fallback values.
601
 *		May be a Unix timestamp or any string that strtotime() can understand.
602
 *		Defaults to 'now'.
603
 * @return array An array relating time zones to "meta-zones"
604
 */
605
function get_sorted_tzids_for_country($country_code, $when = 'now')
606
{
607
	static $country_tzids = array();
608
609
	/*
610
		This array lists all the individual time zones in each country,
611
		sorted by population (as reported in statistics available on
612
		Wikipedia in November 2020). Sorting this way enables us to
613
		consistently select the most appropriate individual time zone to
614
		represent all others that share its DST transition rules and values.
615
		For example, this ensures that New York will be preferred over
616
		random small towns in Indiana.
617
618
		If future versions of the time zone database add new time zone
619
		identifiers beyond those included here, they should be added to this
620
		list as appropriate. However, SMF will gracefully handle unexpected
621
		new time zones, so nothing will break in the meantime.
622
	 */
623
	$sorted_tzids = array(
624
		// '??' means international.
625
		'??' => array(
626
			'UTC',
627
		),
628
		'AD' => array(
629
			'Europe/Andorra',
630
		),
631
		'AE' => array(
632
			'Asia/Dubai',
633
		),
634
		'AF' => array(
635
			'Asia/Kabul',
636
		),
637
		'AG' => array(
638
			'America/Antigua',
639
		),
640
		'AI' => array(
641
			'America/Anguilla',
642
		),
643
		'AL' => array(
644
			'Europe/Tirane',
645
		),
646
		'AM' => array(
647
			'Asia/Yerevan',
648
		),
649
		'AO' => array(
650
			'Africa/Luanda',
651
		),
652
		'AQ' => array(
653
			// Sorted based on summer population.
654
			'Antarctica/McMurdo',
655
			'Antarctica/Casey',
656
			'Antarctica/Davis',
657
			'Antarctica/Mawson',
658
			'Antarctica/Rothera',
659
			'Antarctica/Syowa',
660
			'Antarctica/Palmer',
661
			'Antarctica/Troll',
662
			'Antarctica/DumontDUrville',
663
			'Antarctica/Vostok',
664
		),
665
		'AR' => array(
666
			'America/Argentina/Buenos_Aires',
667
			'America/Argentina/Cordoba',
668
			'America/Argentina/Tucuman',
669
			'America/Argentina/Salta',
670
			'America/Argentina/Jujuy',
671
			'America/Argentina/La_Rioja',
672
			'America/Argentina/San_Luis',
673
			'America/Argentina/Catamarca',
674
			'America/Argentina/Mendoza',
675
			'America/Argentina/San_Juan',
676
			'America/Argentina/Rio_Gallegos',
677
			'America/Argentina/Ushuaia',
678
		),
679
		'AS' => array(
680
			'Pacific/Pago_Pago',
681
		),
682
		'AT' => array(
683
			'Europe/Vienna',
684
		),
685
		'AU' => array(
686
			'Australia/Sydney',
687
			'Australia/Melbourne',
688
			'Australia/Brisbane',
689
			'Australia/Perth',
690
			'Australia/Adelaide',
691
			'Australia/Hobart',
692
			'Australia/Darwin',
693
			'Australia/Broken_Hill',
694
			'Australia/Currie',
695
			'Australia/Lord_Howe',
696
			'Australia/Eucla',
697
			'Australia/Lindeman',
698
			'Antarctica/Macquarie',
699
		),
700
		'AW' => array(
701
			'America/Aruba',
702
		),
703
		'AX' => array(
704
			'Europe/Mariehamn',
705
		),
706
		'AZ' => array(
707
			'Asia/Baku',
708
		),
709
		'BA' => array(
710
			'Europe/Sarajevo',
711
		),
712
		'BB' => array(
713
			'America/Barbados',
714
		),
715
		'BD' => array(
716
			'Asia/Dhaka',
717
		),
718
		'BE' => array(
719
			'Europe/Brussels',
720
		),
721
		'BF' => array(
722
			'Africa/Ouagadougou',
723
		),
724
		'BG' => array(
725
			'Europe/Sofia',
726
		),
727
		'BH' => array(
728
			'Asia/Bahrain',
729
		),
730
		'BI' => array(
731
			'Africa/Bujumbura',
732
		),
733
		'BJ' => array(
734
			'Africa/Porto-Novo',
735
		),
736
		'BL' => array(
737
			'America/St_Barthelemy',
738
		),
739
		'BM' => array(
740
			'Atlantic/Bermuda',
741
		),
742
		'BN' => array(
743
			'Asia/Brunei',
744
		),
745
		'BO' => array(
746
			'America/La_Paz',
747
		),
748
		'BQ' => array(
749
			'America/Kralendijk',
750
		),
751
		'BR' => array(
752
			'America/Sao_Paulo',
753
			'America/Bahia',
754
			'America/Fortaleza',
755
			'America/Manaus',
756
			'America/Recife',
757
			'America/Belem',
758
			'America/Maceio',
759
			'America/Campo_Grande',
760
			'America/Cuiaba',
761
			'America/Porto_Velho',
762
			'America/Rio_Branco',
763
			'America/Boa_Vista',
764
			'America/Santarem',
765
			'America/Araguaina',
766
			'America/Eirunepe',
767
			'America/Noronha',
768
		),
769
		'BS' => array(
770
			'America/Nassau',
771
		),
772
		'BT' => array(
773
			'Asia/Thimphu',
774
		),
775
		'BW' => array(
776
			'Africa/Gaborone',
777
		),
778
		'BY' => array(
779
			'Europe/Minsk',
780
		),
781
		'BZ' => array(
782
			'America/Belize',
783
		),
784
		'CA' => array(
785
			'America/Toronto',
786
			'America/Vancouver',
787
			'America/Edmonton',
788
			'America/Winnipeg',
789
			'America/Halifax',
790
			'America/Regina',
791
			'America/St_Johns',
792
			'America/Moncton',
793
			'America/Thunder_Bay',
794
			'America/Whitehorse',
795
			'America/Glace_Bay',
796
			'America/Yellowknife',
797
			'America/Swift_Current',
798
			'America/Dawson_Creek',
799
			'America/Goose_Bay',
800
			'America/Iqaluit',
801
			'America/Creston',
802
			'America/Fort_Nelson',
803
			'America/Inuvik',
804
			'America/Atikokan',
805
			'America/Rankin_Inlet',
806
			'America/Nipigon',
807
			'America/Cambridge_Bay',
808
			'America/Pangnirtung',
809
			'America/Dawson',
810
			'America/Blanc-Sablon',
811
			'America/Rainy_River',
812
			'America/Resolute',
813
		),
814
		'CC' => array(
815
			'Indian/Cocos',
816
		),
817
		'CD' => array(
818
			'Africa/Kinshasa',
819
			'Africa/Lubumbashi',
820
		),
821
		'CF' => array(
822
			'Africa/Bangui',
823
		),
824
		'CG' => array(
825
			'Africa/Brazzaville',
826
		),
827
		'CH' => array(
828
			'Europe/Zurich',
829
		),
830
		'CI' => array(
831
			'Africa/Abidjan',
832
		),
833
		'CK' => array(
834
			'Pacific/Rarotonga',
835
		),
836
		'CL' => array(
837
			'America/Santiago',
838
			'America/Punta_Arenas',
839
			'Pacific/Easter',
840
		),
841
		'CM' => array(
842
			'Africa/Douala',
843
		),
844
		'CN' => array(
845
			'Asia/Shanghai',
846
			'Asia/Urumqi',
847
		),
848
		'CO' => array(
849
			'America/Bogota',
850
		),
851
		'CR' => array(
852
			'America/Costa_Rica',
853
		),
854
		'CU' => array(
855
			'America/Havana',
856
		),
857
		'CV' => array(
858
			'Atlantic/Cape_Verde',
859
		),
860
		'CW' => array(
861
			'America/Curacao',
862
		),
863
		'CX' => array(
864
			'Indian/Christmas',
865
		),
866
		'CY' => array(
867
			'Asia/Nicosia',
868
			'Asia/Famagusta',
869
		),
870
		'CZ' => array(
871
			'Europe/Prague',
872
		),
873
		'DE' => array(
874
			'Europe/Berlin',
875
			'Europe/Busingen',
876
		),
877
		'DJ' => array(
878
			'Africa/Djibouti',
879
		),
880
		'DK' => array(
881
			'Europe/Copenhagen',
882
		),
883
		'DM' => array(
884
			'America/Dominica',
885
		),
886
		'DO' => array(
887
			'America/Santo_Domingo',
888
		),
889
		'DZ' => array(
890
			'Africa/Algiers',
891
		),
892
		'EC' => array(
893
			'America/Guayaquil',
894
			'Pacific/Galapagos',
895
		),
896
		'EE' => array(
897
			'Europe/Tallinn',
898
		),
899
		'EG' => array(
900
			'Africa/Cairo',
901
		),
902
		'EH' => array(
903
			'Africa/El_Aaiun',
904
		),
905
		'ER' => array(
906
			'Africa/Asmara',
907
		),
908
		'ES' => array(
909
			'Europe/Madrid',
910
			'Atlantic/Canary',
911
			'Africa/Ceuta',
912
		),
913
		'ET' => array(
914
			'Africa/Addis_Ababa',
915
		),
916
		'FI' => array(
917
			'Europe/Helsinki',
918
		),
919
		'FJ' => array(
920
			'Pacific/Fiji',
921
		),
922
		'FK' => array(
923
			'Atlantic/Stanley',
924
		),
925
		'FM' => array(
926
			'Pacific/Chuuk',
927
			'Pacific/Kosrae',
928
			'Pacific/Pohnpei',
929
		),
930
		'FO' => array(
931
			'Atlantic/Faroe',
932
		),
933
		'FR' => array(
934
			'Europe/Paris',
935
		),
936
		'GA' => array(
937
			'Africa/Libreville',
938
		),
939
		'GB' => array(
940
			'Europe/London',
941
		),
942
		'GD' => array(
943
			'America/Grenada',
944
		),
945
		'GE' => array(
946
			'Asia/Tbilisi',
947
		),
948
		'GF' => array(
949
			'America/Cayenne',
950
		),
951
		'GG' => array(
952
			'Europe/Guernsey',
953
		),
954
		'GH' => array(
955
			'Africa/Accra',
956
		),
957
		'GI' => array(
958
			'Europe/Gibraltar',
959
		),
960
		'GL' => array(
961
			'America/Nuuk',
962
			'America/Thule',
963
			'America/Scoresbysund',
964
			'America/Danmarkshavn',
965
		),
966
		'GM' => array(
967
			'Africa/Banjul',
968
		),
969
		'GN' => array(
970
			'Africa/Conakry',
971
		),
972
		'GP' => array(
973
			'America/Guadeloupe',
974
		),
975
		'GQ' => array(
976
			'Africa/Malabo',
977
		),
978
		'GR' => array(
979
			'Europe/Athens',
980
		),
981
		'GS' => array(
982
			'Atlantic/South_Georgia',
983
		),
984
		'GT' => array(
985
			'America/Guatemala',
986
		),
987
		'GU' => array(
988
			'Pacific/Guam',
989
		),
990
		'GW' => array(
991
			'Africa/Bissau',
992
		),
993
		'GY' => array(
994
			'America/Guyana',
995
		),
996
		'HK' => array(
997
			'Asia/Hong_Kong',
998
		),
999
		'HN' => array(
1000
			'America/Tegucigalpa',
1001
		),
1002
		'HR' => array(
1003
			'Europe/Zagreb',
1004
		),
1005
		'HT' => array(
1006
			'America/Port-au-Prince',
1007
		),
1008
		'HU' => array(
1009
			'Europe/Budapest',
1010
		),
1011
		'ID' => array(
1012
			'Asia/Jakarta',
1013
			'Asia/Makassar',
1014
			'Asia/Pontianak',
1015
			'Asia/Jayapura',
1016
		),
1017
		'IE' => array(
1018
			'Europe/Dublin',
1019
		),
1020
		'IL' => array(
1021
			'Asia/Jerusalem',
1022
		),
1023
		'IM' => array(
1024
			'Europe/Isle_of_Man',
1025
		),
1026
		'IN' => array(
1027
			'Asia/Kolkata',
1028
		),
1029
		'IO' => array(
1030
			'Indian/Chagos',
1031
		),
1032
		'IQ' => array(
1033
			'Asia/Baghdad',
1034
		),
1035
		'IR' => array(
1036
			'Asia/Tehran',
1037
		),
1038
		'IS' => array(
1039
			'Atlantic/Reykjavik',
1040
		),
1041
		'IT' => array(
1042
			'Europe/Rome',
1043
		),
1044
		'JE' => array(
1045
			'Europe/Jersey',
1046
		),
1047
		'JM' => array(
1048
			'America/Jamaica',
1049
		),
1050
		'JO' => array(
1051
			'Asia/Amman',
1052
		),
1053
		'JP' => array(
1054
			'Asia/Tokyo',
1055
		),
1056
		'KE' => array(
1057
			'Africa/Nairobi',
1058
		),
1059
		'KG' => array(
1060
			'Asia/Bishkek',
1061
		),
1062
		'KH' => array(
1063
			'Asia/Phnom_Penh',
1064
		),
1065
		'KI' => array(
1066
			'Pacific/Tarawa',
1067
			'Pacific/Kiritimati',
1068
			'Pacific/Kanton',
1069
			'Pacific/Enderbury',
1070
		),
1071
		'KM' => array(
1072
			'Indian/Comoro',
1073
		),
1074
		'KN' => array(
1075
			'America/St_Kitts',
1076
		),
1077
		'KP' => array(
1078
			'Asia/Pyongyang',
1079
		),
1080
		'KR' => array(
1081
			'Asia/Seoul',
1082
		),
1083
		'KW' => array(
1084
			'Asia/Kuwait',
1085
		),
1086
		'KY' => array(
1087
			'America/Cayman',
1088
		),
1089
		'KZ' => array(
1090
			'Asia/Almaty',
1091
			'Asia/Aqtobe',
1092
			'Asia/Atyrau',
1093
			'Asia/Qostanay',
1094
			'Asia/Qyzylorda',
1095
			'Asia/Aqtau',
1096
			'Asia/Oral',
1097
		),
1098
		'LA' => array(
1099
			'Asia/Vientiane',
1100
		),
1101
		'LB' => array(
1102
			'Asia/Beirut',
1103
		),
1104
		'LC' => array(
1105
			'America/St_Lucia',
1106
		),
1107
		'LI' => array(
1108
			'Europe/Vaduz',
1109
		),
1110
		'LK' => array(
1111
			'Asia/Colombo',
1112
		),
1113
		'LR' => array(
1114
			'Africa/Monrovia',
1115
		),
1116
		'LS' => array(
1117
			'Africa/Maseru',
1118
		),
1119
		'LT' => array(
1120
			'Europe/Vilnius',
1121
		),
1122
		'LU' => array(
1123
			'Europe/Luxembourg',
1124
		),
1125
		'LV' => array(
1126
			'Europe/Riga',
1127
		),
1128
		'LY' => array(
1129
			'Africa/Tripoli',
1130
		),
1131
		'MA' => array(
1132
			'Africa/Casablanca',
1133
		),
1134
		'MC' => array(
1135
			'Europe/Monaco',
1136
		),
1137
		'MD' => array(
1138
			'Europe/Chisinau',
1139
		),
1140
		'ME' => array(
1141
			'Europe/Podgorica',
1142
		),
1143
		'MF' => array(
1144
			'America/Marigot',
1145
		),
1146
		'MG' => array(
1147
			'Indian/Antananarivo',
1148
		),
1149
		'MH' => array(
1150
			'Pacific/Majuro',
1151
			'Pacific/Kwajalein',
1152
		),
1153
		'MK' => array(
1154
			'Europe/Skopje',
1155
		),
1156
		'ML' => array(
1157
			'Africa/Bamako',
1158
		),
1159
		'MM' => array(
1160
			'Asia/Yangon',
1161
		),
1162
		'MN' => array(
1163
			'Asia/Ulaanbaatar',
1164
			'Asia/Choibalsan',
1165
			'Asia/Hovd',
1166
		),
1167
		'MO' => array(
1168
			'Asia/Macau',
1169
		),
1170
		'MP' => array(
1171
			'Pacific/Saipan',
1172
		),
1173
		'MQ' => array(
1174
			'America/Martinique',
1175
		),
1176
		'MR' => array(
1177
			'Africa/Nouakchott',
1178
		),
1179
		'MS' => array(
1180
			'America/Montserrat',
1181
		),
1182
		'MT' => array(
1183
			'Europe/Malta',
1184
		),
1185
		'MU' => array(
1186
			'Indian/Mauritius',
1187
		),
1188
		'MV' => array(
1189
			'Indian/Maldives',
1190
		),
1191
		'MW' => array(
1192
			'Africa/Blantyre',
1193
		),
1194
		'MX' => array(
1195
			'America/Mexico_City',
1196
			'America/Tijuana',
1197
			'America/Monterrey',
1198
			'America/Chihuahua',
1199
			'America/Merida',
1200
			'America/Hermosillo',
1201
			'America/Cancun',
1202
			'America/Matamoros',
1203
			'America/Mazatlan',
1204
			'America/Bahia_Banderas',
1205
			'America/Ojinaga',
1206
		),
1207
		'MY' => array(
1208
			'Asia/Kuala_Lumpur',
1209
			'Asia/Kuching',
1210
		),
1211
		'MZ' => array(
1212
			'Africa/Maputo',
1213
		),
1214
		'NA' => array(
1215
			'Africa/Windhoek',
1216
		),
1217
		'NC' => array(
1218
			'Pacific/Noumea',
1219
		),
1220
		'NE' => array(
1221
			'Africa/Niamey',
1222
		),
1223
		'NF' => array(
1224
			'Pacific/Norfolk',
1225
		),
1226
		'NG' => array(
1227
			'Africa/Lagos',
1228
		),
1229
		'NI' => array(
1230
			'America/Managua',
1231
		),
1232
		'NL' => array(
1233
			'Europe/Amsterdam',
1234
		),
1235
		'NO' => array(
1236
			'Europe/Oslo',
1237
		),
1238
		'NP' => array(
1239
			'Asia/Kathmandu',
1240
		),
1241
		'NR' => array(
1242
			'Pacific/Nauru',
1243
		),
1244
		'NU' => array(
1245
			'Pacific/Niue',
1246
		),
1247
		'NZ' => array(
1248
			'Pacific/Auckland',
1249
			'Pacific/Chatham',
1250
		),
1251
		'OM' => array(
1252
			'Asia/Muscat',
1253
		),
1254
		'PA' => array(
1255
			'America/Panama',
1256
		),
1257
		'PE' => array(
1258
			'America/Lima',
1259
		),
1260
		'PF' => array(
1261
			'Pacific/Tahiti',
1262
			'Pacific/Marquesas',
1263
			'Pacific/Gambier',
1264
		),
1265
		'PG' => array(
1266
			'Pacific/Port_Moresby',
1267
			'Pacific/Bougainville',
1268
		),
1269
		'PH' => array(
1270
			'Asia/Manila',
1271
		),
1272
		'PK' => array(
1273
			'Asia/Karachi',
1274
		),
1275
		'PL' => array(
1276
			'Europe/Warsaw',
1277
		),
1278
		'PM' => array(
1279
			'America/Miquelon',
1280
		),
1281
		'PN' => array(
1282
			'Pacific/Pitcairn',
1283
		),
1284
		'PR' => array(
1285
			'America/Puerto_Rico',
1286
		),
1287
		'PS' => array(
1288
			'Asia/Gaza',
1289
			'Asia/Hebron',
1290
		),
1291
		'PT' => array(
1292
			'Europe/Lisbon',
1293
			'Atlantic/Madeira',
1294
			'Atlantic/Azores',
1295
		),
1296
		'PW' => array(
1297
			'Pacific/Palau',
1298
		),
1299
		'PY' => array(
1300
			'America/Asuncion',
1301
		),
1302
		'QA' => array(
1303
			'Asia/Qatar',
1304
		),
1305
		'RE' => array(
1306
			'Indian/Reunion',
1307
		),
1308
		'RO' => array(
1309
			'Europe/Bucharest',
1310
		),
1311
		'RS' => array(
1312
			'Europe/Belgrade',
1313
		),
1314
		'RU' => array(
1315
			'Europe/Moscow',
1316
			'Asia/Novosibirsk',
1317
			'Asia/Yekaterinburg',
1318
			'Europe/Samara',
1319
			'Asia/Omsk',
1320
			'Asia/Krasnoyarsk',
1321
			'Europe/Volgograd',
1322
			'Europe/Saratov',
1323
			'Asia/Barnaul',
1324
			'Europe/Ulyanovsk',
1325
			'Asia/Irkutsk',
1326
			'Asia/Vladivostok',
1327
			'Asia/Tomsk',
1328
			'Asia/Novokuznetsk',
1329
			'Europe/Astrakhan',
1330
			'Europe/Kirov',
1331
			'Europe/Kaliningrad',
1332
			'Asia/Chita',
1333
			'Asia/Yakutsk',
1334
			'Asia/Sakhalin',
1335
			'Asia/Kamchatka',
1336
			'Asia/Magadan',
1337
			'Asia/Anadyr',
1338
			'Asia/Khandyga',
1339
			'Asia/Ust-Nera',
1340
			'Asia/Srednekolymsk',
1341
		),
1342
		'RW' => array(
1343
			'Africa/Kigali',
1344
		),
1345
		'SA' => array(
1346
			'Asia/Riyadh',
1347
		),
1348
		'SB' => array(
1349
			'Pacific/Guadalcanal',
1350
		),
1351
		'SC' => array(
1352
			'Indian/Mahe',
1353
		),
1354
		'SD' => array(
1355
			'Africa/Khartoum',
1356
		),
1357
		'SE' => array(
1358
			'Europe/Stockholm',
1359
		),
1360
		'SG' => array(
1361
			'Asia/Singapore',
1362
		),
1363
		'SH' => array(
1364
			'Atlantic/St_Helena',
1365
		),
1366
		'SI' => array(
1367
			'Europe/Ljubljana',
1368
		),
1369
		'SJ' => array(
1370
			'Arctic/Longyearbyen',
1371
		),
1372
		'SK' => array(
1373
			'Europe/Bratislava',
1374
		),
1375
		'SL' => array(
1376
			'Africa/Freetown',
1377
		),
1378
		'SM' => array(
1379
			'Europe/San_Marino',
1380
		),
1381
		'SN' => array(
1382
			'Africa/Dakar',
1383
		),
1384
		'SO' => array(
1385
			'Africa/Mogadishu',
1386
		),
1387
		'SR' => array(
1388
			'America/Paramaribo',
1389
		),
1390
		'SS' => array(
1391
			'Africa/Juba',
1392
		),
1393
		'ST' => array(
1394
			'Africa/Sao_Tome',
1395
		),
1396
		'SV' => array(
1397
			'America/El_Salvador',
1398
		),
1399
		'SX' => array(
1400
			'America/Lower_Princes',
1401
		),
1402
		'SY' => array(
1403
			'Asia/Damascus',
1404
		),
1405
		'SZ' => array(
1406
			'Africa/Mbabane',
1407
		),
1408
		'TC' => array(
1409
			'America/Grand_Turk',
1410
		),
1411
		'TD' => array(
1412
			'Africa/Ndjamena',
1413
		),
1414
		'TF' => array(
1415
			'Indian/Kerguelen',
1416
		),
1417
		'TG' => array(
1418
			'Africa/Lome',
1419
		),
1420
		'TH' => array(
1421
			'Asia/Bangkok',
1422
		),
1423
		'TJ' => array(
1424
			'Asia/Dushanbe',
1425
		),
1426
		'TK' => array(
1427
			'Pacific/Fakaofo',
1428
		),
1429
		'TL' => array(
1430
			'Asia/Dili',
1431
		),
1432
		'TM' => array(
1433
			'Asia/Ashgabat',
1434
		),
1435
		'TN' => array(
1436
			'Africa/Tunis',
1437
		),
1438
		'TO' => array(
1439
			'Pacific/Tongatapu',
1440
		),
1441
		'TR' => array(
1442
			'Europe/Istanbul',
1443
		),
1444
		'TT' => array(
1445
			'America/Port_of_Spain',
1446
		),
1447
		'TV' => array(
1448
			'Pacific/Funafuti',
1449
		),
1450
		'TW' => array(
1451
			'Asia/Taipei',
1452
		),
1453
		'TZ' => array(
1454
			'Africa/Dar_es_Salaam',
1455
		),
1456
		'UA' => array(
1457
			'Europe/Kiev',
1458
			'Europe/Zaporozhye',
1459
			'Europe/Simferopol',
1460
			'Europe/Uzhgorod',
1461
		),
1462
		'UG' => array(
1463
			'Africa/Kampala',
1464
		),
1465
		'UM' => array(
1466
			'Pacific/Midway',
1467
			'Pacific/Wake',
1468
		),
1469
		'US' => array(
1470
			'America/New_York',
1471
			'America/Los_Angeles',
1472
			'America/Chicago',
1473
			'America/Denver',
1474
			'America/Phoenix',
1475
			'America/Indiana/Indianapolis',
1476
			'America/Detroit',
1477
			'America/Kentucky/Louisville',
1478
			'Pacific/Honolulu',
1479
			'America/Anchorage',
1480
			'America/Boise',
1481
			'America/Juneau',
1482
			'America/Indiana/Vincennes',
1483
			'America/Sitka',
1484
			'America/Menominee',
1485
			'America/Indiana/Tell_City',
1486
			'America/Kentucky/Monticello',
1487
			'America/Nome',
1488
			'America/Indiana/Knox',
1489
			'America/North_Dakota/Beulah',
1490
			'America/Indiana/Winamac',
1491
			'America/Indiana/Petersburg',
1492
			'America/Indiana/Vevay',
1493
			'America/Metlakatla',
1494
			'America/North_Dakota/New_Salem',
1495
			'America/Indiana/Marengo',
1496
			'America/Yakutat',
1497
			'America/North_Dakota/Center',
1498
			'America/Adak',
1499
		),
1500
		'UY' => array(
1501
			'America/Montevideo',
1502
		),
1503
		'UZ' => array(
1504
			'Asia/Tashkent',
1505
			'Asia/Samarkand',
1506
		),
1507
		'VA' => array(
1508
			'Europe/Vatican',
1509
		),
1510
		'VC' => array(
1511
			'America/St_Vincent',
1512
		),
1513
		'VE' => array(
1514
			'America/Caracas',
1515
		),
1516
		'VG' => array(
1517
			'America/Tortola',
1518
		),
1519
		'VI' => array(
1520
			'America/St_Thomas',
1521
		),
1522
		'VN' => array(
1523
			'Asia/Ho_Chi_Minh',
1524
		),
1525
		'VU' => array(
1526
			'Pacific/Efate',
1527
		),
1528
		'WF' => array(
1529
			'Pacific/Wallis',
1530
		),
1531
		'WS' => array(
1532
			'Pacific/Apia',
1533
		),
1534
		'YE' => array(
1535
			'Asia/Aden',
1536
		),
1537
		'YT' => array(
1538
			'Indian/Mayotte',
1539
		),
1540
		'ZA' => array(
1541
			'Africa/Johannesburg',
1542
		),
1543
		'ZM' => array(
1544
			'Africa/Lusaka',
1545
		),
1546
		'ZW' => array(
1547
			'Africa/Harare',
1548
		),
1549
	);
1550
1551
	// Just in case...
1552
	$country_code = strtoupper(trim($country_code));
1553
1554
	// Avoid unnecessary repetition.
1555
	if (!isset($country_tzids[$country_code]))
1556
	{
1557
		call_integration_hook('integrate_country_timezones', array(&$sorted_tzids, $country_code, $when));
1558
1559
		$country_tzids[$country_code] = isset($sorted_tzids[$country_code]) ? $sorted_tzids[$country_code] : array();
1560
1561
		// If something goes wrong, we want an empty array, not false.
1562
		$recognized_country_tzids = array_filter((array) @timezone_identifiers_list(DateTimeZone::PER_COUNTRY, $country_code));
0 ignored issues
show
Are you sure the usage of timezone_identifiers_lis...COUNTRY, $country_code) is correct as it seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
1563
1564
		// Make sure that no time zones are missing.
1565
		$country_tzids[$country_code] = array_unique(array_merge($country_tzids[$country_code], array_intersect($recognized_country_tzids, timezone_identifiers_list())));
0 ignored issues
show
timezone_identifiers_list() of type void is incompatible with the type array expected by parameter $arrays of array_intersect(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1565
		$country_tzids[$country_code] = array_unique(array_merge($country_tzids[$country_code], array_intersect($recognized_country_tzids, /** @scrutinizer ignore-type */ timezone_identifiers_list())));
Loading history...
Are you sure the usage of timezone_identifiers_list() is correct as it seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
1566
1567
		// Get fallbacks where necessary.
1568
		$country_tzids[$country_code] = array_values(get_tzid_fallbacks($country_tzids[$country_code], $when));
1569
1570
		// Filter out any time zones that are still undefined.
1571
		$country_tzids[$country_code] = array_intersect(array_filter($country_tzids[$country_code]), timezone_identifiers_list(DateTimeZone::ALL_WITH_BC));
0 ignored issues
show
Are you sure the usage of timezone_identifiers_lis...eTimeZone::ALL_WITH_BC) is correct as it seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
1572
	}
1573
1574
	return $country_tzids[$country_code];
1575
}
1576
1577
/**
1578
 * Checks a list of time zone identifiers to make sure they are all defined in
1579
 * the installed version of the time zone database, and returns an array of
1580
 * key-value substitution pairs.
1581
 *
1582
 * For defined time zone identifiers, the substitution value will be identical
1583
 * to the original value. For undefined ones, the substitute will be a time zone
1584
 * identifier that was equivalent to the missing one at the specified time, or
1585
 * an empty string if there was no equivalent at that time.
1586
 *
1587
 * Note: These fallbacks do not need to include every new time zone ever. They
1588
 * only need to cover any that are used in $tzid_metazones.
1589
 *
1590
 * To find the date & time when a new time zone comes into effect, check
1591
 * the TZDB changelog at https://data.iana.org/time-zones/tzdb/NEWS
1592
 *
1593
 * @param array $tzids The time zone identifiers to check.
1594
 * @param string $when The date/time used to determine substitute values.
1595
 *		May be a Unix timestamp or any string that strtotime() can understand.
1596
 *		Defaults to 'now'.
1597
 * @return array Substitute values for any missing time zone identifiers.
1598
 */
1599
function get_tzid_fallbacks($tzids, $when = 'now')
1600
{
1601
	$tzids = (array) $tzids;
1602
1603
	$when = is_numeric($when) ? intval($when) : (is_int(@strtotime($when)) ? strtotime($when) : time());
1604
1605
	// 'ts' is the timestamp when the substitution first becomes valid.
1606
	// 'tzid' is the alternative time zone identifier to use.
1607
	$fallbacks = array(
1608
		// 1. Simple renames. PHP_INT_MIN because these are valid for all dates.
1609
		'Asia/Kolkata' => array(
1610
			array(
1611
				'ts' => PHP_INT_MIN,
1612
				'tzid' => 'Asia/Calcutta',
1613
			),
1614
		),
1615
		'Pacific/Chuuk' => array(
1616
			array(
1617
				'ts' => PHP_INT_MIN,
1618
				'tzid' => 'Pacific/Truk',
1619
			),
1620
		),
1621
		'Pacific/Kanton' => array(
1622
			array(
1623
				'ts' => PHP_INT_MIN,
1624
				'tzid' => 'Pacific/Enderbury',
1625
			),
1626
		),
1627
		'Pacific/Pohnpei' => array(
1628
			array(
1629
				'ts' => PHP_INT_MIN,
1630
				'tzid' => 'Pacific/Ponape',
1631
			),
1632
		),
1633
		'Asia/Yangon' => array(
1634
			array(
1635
				'ts' => PHP_INT_MIN,
1636
				'tzid' => 'Asia/Rangoon',
1637
			),
1638
		),
1639
		'America/Nuuk' => array(
1640
			array(
1641
				'ts' => PHP_INT_MIN,
1642
				'tzid' => 'America/Godthab',
1643
			),
1644
		),
1645
1646
		// 2. Newly created time zones.
1647
1648
		// The same as Tasmania, except it stayed on DST all year in 2010.
1649
		// Australia/Tasmania is an otherwise unused backwards compatibility
1650
		// link to Australia/Hobart, so we can borrow it here without conflict.
1651
		'Antarctica/Macquarie' => array(
1652
			array(
1653
				'ts' => PHP_INT_MIN,
1654
				'tzid' => 'Australia/Tasmania',
1655
			),
1656
			array(
1657
				'ts' => strtotime('2010-04-03T16:00:00+0000'),
1658
				'tzid' => 'Etc/GMT-11',
1659
			),
1660
			array(
1661
				'ts' => strtotime('2011-04-07T17:00:00+0000'),
1662
				'tzid' => 'Australia/Tasmania',
1663
			),
1664
		),
1665
1666
		// This place uses two hours for DST. No substitutes are possible.
1667
		'Antarctica/Troll' => array(
1668
			array(
1669
				'ts' => PHP_INT_MIN,
1670
				'tzid' => '',
1671
			),
1672
		),
1673
1674
		// Diverged from Pacific/Port_Moresby in version 2014i.
1675
		'Pacific/Bougainville' => array(
1676
			// Before the divergence, we don't actually need this one at all.
1677
			array(
1678
				'ts' => PHP_INT_MIN,
1679
				'tzid' => '',
1680
			),
1681
			// For dates after divergence, it is the same as Pacific/Kosrae.
1682
			// If this ever ceases to be true, add another entry.
1683
			array(
1684
				'ts' => strtotime('2014-12-27T16:00:00+0000'),
1685
				'tzid' => 'Pacific/Kosrae',
1686
			),
1687
		),
1688
1689
		// Diverged from America/Santiago in version 2017a.
1690
		'America/Punta_Arenas' => array(
1691
			// Before the divergence, we don't actually need this one at all.
1692
			array(
1693
				'ts' => PHP_INT_MIN,
1694
				'tzid' => '',
1695
			),
1696
			// For dates after divergence, it is the same as Antarctica/Palmer.
1697
			// If this ever ceases to be true, add another entry.
1698
			array(
1699
				'ts' => strtotime('2017-05-14T03:00:00+0000'),
1700
				'tzid' => 'Antarctica/Palmer',
1701
			),
1702
		),
1703
	);
1704
1705
	$missing = array_diff($tzids, timezone_identifiers_list(DateTimeZone::ALL_WITH_BC));
0 ignored issues
show
timezone_identifiers_lis...eTimeZone::ALL_WITH_BC) of type void is incompatible with the type array expected by parameter $excludes of array_diff(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1705
	$missing = array_diff($tzids, /** @scrutinizer ignore-type */ timezone_identifiers_list(DateTimeZone::ALL_WITH_BC));
Loading history...
Are you sure the usage of timezone_identifiers_lis...eTimeZone::ALL_WITH_BC) is correct as it seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
1706
1707
	call_integration_hook('integrate_timezone_fallbacks', array(&$fallbacks, &$missing, $tzids, $when));
1708
1709
	$replacements = array();
1710
1711
	foreach ($tzids as $tzid)
1712
	{
1713
		// Not missing.
1714
		if (!in_array($tzid, $missing))
1715
			$replacements[$tzid] = $tzid;
1716
1717
		// Missing and we have no fallback.
1718
		elseif (empty($fallbacks[$tzid]))
1719
			$replacements[$tzid] = '';
1720
1721
		// Missing, but we have a fallback.
1722
		else
1723
		{
1724
			usort(
1725
				$fallbacks[$tzid],
1726
				function ($a, $b)
1727
				{
1728
					return $a['ts'] > $b['ts'];
1729
				}
1730
			);
1731
1732
			foreach ($fallbacks[$tzid] as $alt)
1733
			{
1734
				if ($when < $alt['ts'])
1735
					break;
1736
1737
				$replacements[$tzid] = $alt['tzid'];
1738
			}
1739
1740
			if (empty($replacements[$tzid]))
1741
				$replacements[$tzid] = '';
1742
		}
1743
	}
1744
1745
	return $replacements;
1746
}
1747
1748
/**
1749
 * Validates a set of two-character ISO 3166-1 country codes.
1750
 *
1751
 * @param array|string $country_codes Array or CSV string of country codes.
1752
 * @param bool $as_csv If true, return CSV string instead of array.
1753
 * @return array|string Array or CSV string of valid country codes.
1754
 */
1755
function validate_iso_country_codes($country_codes, $as_csv = false)
1756
{
1757
	if (is_string($country_codes))
1758
		$country_codes = explode(',', $country_codes);
1759
	else
1760
		$country_codes = array_map('strval', (array) $country_codes);
1761
1762
	foreach ($country_codes as $key => $country_code)
1763
	{
1764
		$country_code = strtoupper(trim($country_code));
1765
		$country_tzids = strlen($country_code) !== 2 ? null : @timezone_identifiers_list(DateTimeZone::PER_COUNTRY, $country_code);
0 ignored issues
show
Are you sure the usage of timezone_identifiers_lis...COUNTRY, $country_code) is correct as it seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
1766
		$country_codes[$key] = empty($country_tzids) ? null : $country_code;
1767
	}
1768
1769
	$country_codes = array_filter($country_codes);
1770
1771
	if (!empty($as_csv))
1772
		$country_codes = implode(',', $country_codes);
1773
1774
	return $country_codes;
1775
}
1776
1777
?>