1#!/usr/bin/env php
2<?php
3
4$windowsZonesUrl = 'http://unicode.org/repos/cldr/trunk/common/supplemental/windowsZones.xml';
5$outputFile = __DIR__ . '/../lib/timezonedata/windowszones.php';
6
7echo "Fetching timezone map from: " . $windowsZonesUrl, "\n";
8
9$data = file_get_contents($windowsZonesUrl);
10
11$xml = simplexml_load_string($data);
12
13$map = [];
14
15foreach ($xml->xpath('//mapZone') as $mapZone) {
16
17    $from = (string)$mapZone['other'];
18    $to = (string)$mapZone['type'];
19
20    list($to) = explode(' ', $to, 2);
21
22    if (!isset($map[$from])) {
23        $map[$from] = $to;
24    }
25
26}
27
28ksort($map);
29echo "Writing to: $outputFile\n";
30
31$f = fopen($outputFile, 'w');
32fwrite($f, "<?php\n\n");
33fwrite($f, "/**\n");
34fwrite($f, " * Automatically generated timezone file\n");
35fwrite($f, " *\n");
36fwrite($f, " * Last update: " . date(DATE_W3C) . "\n");
37fwrite($f, " * Source: " . $windowsZonesUrl . "\n");
38fwrite($f, " *\n");
39fwrite($f, " * @copyright Copyright (C) fruux GmbH (https://fruux.com/).\n");
40fwrite($f, " * @license http://sabre.io/license/ Modified BSD License\n");
41fwrite($f, " */\n");
42fwrite($f, "\n");
43fwrite($f, "return ");
44fwrite($f, var_export($map, true) . ';');
45fclose($f);
46
47echo "Formatting\n";
48
49exec(__DIR__ . '/sabre-cs-fixer fix ' . escapeshellarg($outputFile));
50
51echo "Done\n";
52