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