fetch_windows_zones.php 1.2 KB

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