1 // Copyright 2013 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
10 // go run genzabbrs.go -output zoneinfo_abbrs_windows.go
28 var filename
= flag
.String("output", "zoneinfo_abbrs_windows.go", "output file name")
30 // getAbbrs finds timezone abbreviations (standard and daylight saving time)
32 func getAbbrs(l
*time
.Location
) (st
, dt
string) {
33 t
:= time
.Date(time
.Now().Year(), 0, 1, 0, 0, 0, 0, l
)
34 abbr1
, off1
:= t
.Zone()
35 for i
:= 0; i
< 12; i
++ {
36 t
= t
.AddDate(0, 1, 0)
37 abbr2
, off2
:= t
.Zone()
39 if off2
-off1
< 0 { // southern hemisphere
40 abbr1
, abbr2
= abbr2
, abbr1
57 func (zs zones
) Len() int { return len(zs
) }
58 func (zs zones
) Swap(i
, j
int) { zs
[i
], zs
[j
] = zs
[j
], zs
[i
] }
59 func (zs zones
) Less(i
, j
int) bool { return zs
[i
].UnixName
< zs
[j
].UnixName
}
61 const wzURL
= "http://unicode.org/cldr/data/common/supplemental/windowsZones.xml"
64 Other
string `xml:"other,attr"`
65 Territory
string `xml:"territory,attr"`
66 Type
string `xml:"type,attr"`
69 type SupplementalData
struct {
70 Zones
[]MapZone
`xml:"windowsZones>mapTimezones>mapZone"`
73 func readWindowsZones() (zones
, error
) {
74 r
, err
:= http
.Get(wzURL
)
80 data
, err
:= ioutil
.ReadAll(r
.Body
)
85 var sd SupplementalData
86 err
= xml
.Unmarshal(data
, &sd
)
91 for _
, z
:= range sd
.Zones
{
92 if z
.Territory
!= "001" {
93 // to avoid dups. I don't know why.
96 l
, err
:= time
.LoadLocation(z
.Type
)
100 st
, dt
:= getAbbrs(l
)
101 zs
= append(zs
, &zone
{
113 zs
, err
:= readWindowsZones()
126 err
= template
.Must(template
.New("prog").Parse(prog
)).Execute(&buf
, v
)
130 data
, err
:= format
.Source(buf
.Bytes())
134 err
= ioutil
.WriteFile(*filename
, data
, 0644)
141 // Copyright 2013 The Go Authors. All rights reserved.
142 // Use of this source code is governed by a BSD-style
143 // license that can be found in the LICENSE file.
145 // Code generated by genzabbrs.go; DO NOT EDIT.
146 // Based on information from {{.URL}}
155 var abbrs = map[string]abbr{
156 {{range .Zs}} "{{.WinName}}": {"{{.StTime}}", "{{.DSTime}}"}, // {{.UnixName}}