aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/sabre/vobject/bin/fetch_windows_zones.php
blob: 1b1fdc37c0543829e417b7917d0f78941953797a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env php
<?php

$windowsZonesUrl = 'http://unicode.org/repos/cldr/trunk/common/supplemental/windowsZones.xml';
$outputFile = __DIR__ . '/../lib/timezonedata/windowszones.php';

echo "Fetching timezone map from: " . $windowsZonesUrl, "\n";

$data = file_get_contents($windowsZonesUrl);

$xml = simplexml_load_string($data);

$map = [];

foreach ($xml->xpath('//mapZone') as $mapZone) {

    $from = (string)$mapZone['other'];
    $to = (string)$mapZone['type'];

    list($to) = explode(' ', $to, 2);

    if (!isset($map[$from])) {
        $map[$from] = $to;
    }

}

ksort($map);
echo "Writing to: $outputFile\n";

$f = fopen($outputFile, 'w');
fwrite($f, "<?php\n\n");
fwrite($f, "/**\n");
fwrite($f, " * Automatically generated timezone file\n");
fwrite($f, " *\n");
fwrite($f, " * Last update: " . date(DATE_W3C) . "\n");
fwrite($f, " * Source: " . $windowsZonesUrl . "\n");
fwrite($f, " *\n");
fwrite($f, " * @copyright Copyright (C) 2011-2015 fruux GmbH (https://fruux.com/).\n");
fwrite($f, " * @license http://sabre.io/license/ Modified BSD License\n");
fwrite($f, " */\n");
fwrite($f, "\n");
fwrite($f, "return ");
fwrite($f, var_export($map, true) . ';');
fclose($f);

echo "Formatting\n";

exec(__DIR__ . '/sabre-cs-fixer fix ' . escapeshellarg($outputFile));

echo "Done\n";