| 1 |
package tzdata |
| 2 |
|
| 3 |
import ( |
| 4 |
"encoding/xml" |
| 5 |
"fmt" |
| 6 |
"io/ioutil" |
| 7 |
"net/http" |
| 8 |
) |
| 9 |
|
| 10 |
const winZonesURL = `https://raw.githubusercontent.com/unicode-org/cldr/master/common/supplemental/windowsZones.xml` |
| 11 |
|
| 12 |
type SupplementalData struct { |
| 13 |
WindowsZones WindowsZones `xml:"windowsZones"` |
| 14 |
} |
| 15 |
type Version struct { |
| 16 |
Number string `xml:"number,attr"` |
| 17 |
} |
| 18 |
type WindowsZones struct { |
| 19 |
MapTimezones []MapTimezones `xml:"mapTimezones"` |
| 20 |
} |
| 21 |
type MapTimezones struct { |
| 22 |
MapZone []MapZone `xml:"mapZone"` |
| 23 |
Type string `xml:"type,attr"` |
| 24 |
} |
| 25 |
type MapZone struct { |
| 26 |
Other string `xml:"other,attr"` |
| 27 |
Territory string `xml:"territory,attr"` |
| 28 |
Type string `xml:"type,attr"` |
| 29 |
} |
| 30 |
|
| 31 |
|
| 32 |
func DownloadWindowsZones() (SupplementalData, error) { |
| 33 |
var data SupplementalData |
| 34 |
|
| 35 |
resp, err := http.Get(winZonesURL) |
| 36 |
if err != nil { |
| 37 |
return data, err |
| 38 |
} |
| 39 |
defer resp.Body.Close() |
| 40 |
|
| 41 |
if resp.StatusCode != http.StatusOK { |
| 42 |
return data, fmt.Errorf("failed to download \"%v\", http error: %v", winZonesURL, resp.StatusCode) |
| 43 |
} |
| 44 |
|
| 45 |
bytes, err := ioutil.ReadAll(resp.Body) |
| 46 |
if err != nil { |
| 47 |
return data, err |
| 48 |
} |
| 49 |
|
| 50 |
xml.Unmarshal(bytes, &data) |
| 51 |
|
| 52 |
return data, nil |
| 53 |
} |