fetch_windows_zones.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/usr/bin/env php
  2. <?php
  3. $windowsZonesUrl = 'https://raw.githubusercontent.com/unicode-org/cldr/master/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) 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 "Formatting\n";
  35. exec(__DIR__.'/../vendor/bin/php-cs-fixer fix '.escapeshellarg($outputFile));
  36. echo "Done\n";