]>
git.immae.eu Git - github/shaarli/Shaarli.git/blob - application/TimeZone.php
3 * Generates a list of available timezone continents and cities.
5 * Two distinct array based on available timezones
6 * and the one selected in the settings:
8 * + list of available continents
9 * + special key 'selected' containing the value of the selected timezone's continent
11 * + list of available cities associated with their continent
12 * + special key 'selected' containing the value of the selected timezone's city (without the continent)
19 * 'selected' => 'Europe',
22 * ['continent' => 'America', 'city' => 'Toronto'],
23 * ['continent' => 'Europe', 'city' => 'Paris'],
24 * 'selected' => 'Paris',
29 * - 'UTC/UTC' is mapped to 'UTC' to form a valid option
30 * - a few timezone cities includes the country/state, such as Argentina/Buenos_Aires
31 * - these arrays are designed to build timezone selects in template files with any HTML structure
33 * @param array $installedTimeZones List of installed timezones as string
34 * @param string $preselectedTimezone preselected timezone (optional)
36 * @return array[] continents and cities
38 function generateTimeZoneData($installedTimeZones, $preselectedTimezone = '')
40 if ($preselectedTimezone == 'UTC') {
41 $pcity = $pcontinent = 'UTC';
43 // Try to split the provided timezone
44 $spos = strpos($preselectedTimezone, '/');
45 $pcontinent = substr($preselectedTimezone, 0, $spos);
46 $pcity = substr($preselectedTimezone, $spos+
1);
51 foreach ($installedTimeZones as $tz) {
55 $spos = strpos($tz, '/');
57 // Ignore invalid timezones
58 if ($spos === false) {
62 $continent = substr($tz, 0, $spos);
63 $city = substr($tz, $spos+
1);
64 $cities[] = ['continent' => $continent, 'city' => $city];
65 $continents[$continent] = true;
68 $continents = array_keys($continents);
69 $continents['selected'] = $pcontinent;
70 $cities['selected'] = $pcity;
72 return [$continents, $cities];
76 * Tells if a continent/city pair form a valid timezone
78 * Note: 'UTC/UTC' is mapped to 'UTC'
80 * @param string $continent the timezone continent
81 * @param string $city the timezone city
83 * @return bool whether continent/city is a valid timezone
85 function isTimeZoneValid($continent, $city)
89 timezone_identifiers_list()