File: generate_windows_timezone_map.php

package info (click to toggle)
phabricator 0~git20190207-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 71,728 kB
  • sloc: php: 552,244; sql: 16,997; ansic: 3,619; yacc: 2,503; sh: 754; xml: 519; lex: 488; cpp: 221; python: 186; makefile: 177; sed: 66
file content (46 lines) | stat: -rwxr-xr-x 990 bytes parent folder | download
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
#!/usr/bin/env php
<?php

$root = dirname(dirname(dirname(__FILE__)));
require_once $root.'/scripts/__init_script__.php';

$xml = $root.'/externals/cldr/cldr_windows_timezones.xml';
$xml = Filesystem::readFile($xml);
$xml = new SimpleXMLElement($xml);

$result_map = array();

$ignore = array(
  'UTC',
  'UTC-11',
  'UTC-02',
  'UTC-08',
  'UTC-09',
  'UTC+12',
);
$ignore = array_fuse($ignore);

$zones = $xml->windowsZones->mapTimezones->mapZone;
foreach ($zones as $zone) {
  $windows_name = (string)$zone['other'];
  $target_name = (string)$zone['type'];

  // Ignore the offset-based timezones from the CLDR map, since we handle
  // these later.
  if (isset($ignore[$windows_name])) {
    continue;
  }

  // We've already seen this timezone so we don't need to add it to the map
  // again.
  if (isset($result_map[$windows_name])) {
    continue;
  }

  $result_map[$windows_name] = $target_name;
}

asort($result_map);

echo id(new PhutilJSON())
  ->encodeFormatted($result_map);