From 1660ece7695a90e178aa08ef6e413811957791d5 Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Tue, 26 Aug 2014 14:45:53 -0700 Subject: [PATCH] time: use go generate rather than Makefile (windows only) Also make genzabbrs.go more self-contained. Also run it (on Linux; does that matter?) to update the table. LGTM=rsc R=rsc, alex.brainman CC=golang-codereviews https://golang.org/cl/128350044 --- src/pkg/time/Makefile | 9 --------- src/pkg/time/genzabbrs.go | 20 +++++++++++++++++--- src/pkg/time/zoneinfo_abbrs_windows.go | 11 ++++++----- src/pkg/time/zoneinfo_windows.go | 2 ++ 4 files changed, 25 insertions(+), 17 deletions(-) delete mode 100644 src/pkg/time/Makefile diff --git a/src/pkg/time/Makefile b/src/pkg/time/Makefile deleted file mode 100644 index cba58e4e03..0000000000 --- a/src/pkg/time/Makefile +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright 2013 The Go Authors. All rights reserved. -# Use of this source code is governed by a BSD-style -# license that can be found in the LICENSE file. - -genzabbrs: genzabbrs.go - go build genzabbrs.go - -windows: genzabbrs - ./genzabbrs | gofmt >zoneinfo_abbrs_windows.go diff --git a/src/pkg/time/genzabbrs.go b/src/pkg/time/genzabbrs.go index 7c637cb43a..9eb0728a42 100644 --- a/src/pkg/time/genzabbrs.go +++ b/src/pkg/time/genzabbrs.go @@ -7,22 +7,26 @@ // // usage: // -// go run genzabbrs.go | gofmt > $GOROOT/src/pkg/time/zoneinfo_abbrs_windows.go +// go run genzabbrs.go -output zoneinfo_abbrs_windows.go // package main import ( + "bytes" "encoding/xml" + "flag" + "go/format" "io/ioutil" "log" "net/http" - "os" "sort" "text/template" "time" ) +var filename = flag.String("output", "zoneinfo_abbrs_windows.go", "output file name") + // getAbbrs finds timezone abbreviations (standard and daylight saving time) // for location l. func getAbbrs(l *time.Location) (st, dt string) { @@ -105,6 +109,7 @@ func readWindowsZones() (zones, error) { } func main() { + flag.Parse() zs, err := readWindowsZones() if err != nil { log.Fatal(err) @@ -117,7 +122,16 @@ func main() { wzURL, zs, } - err = template.Must(template.New("prog").Parse(prog)).Execute(os.Stdout, v) + var buf bytes.Buffer + err = template.Must(template.New("prog").Parse(prog)).Execute(&buf, v) + if err != nil { + log.Fatal(err) + } + data, err := format.Source(buf.Bytes()) + if err != nil { + log.Fatal(err) + } + err = ioutil.WriteFile(*filename, data, 0644) if err != nil { log.Fatal(err) } diff --git a/src/pkg/time/zoneinfo_abbrs_windows.go b/src/pkg/time/zoneinfo_abbrs_windows.go index 80334371fe..df0c10e91c 100644 --- a/src/pkg/time/zoneinfo_abbrs_windows.go +++ b/src/pkg/time/zoneinfo_abbrs_windows.go @@ -13,15 +13,16 @@ type abbr struct { } var abbrs = map[string]abbr{ - "Egypt Standard Time": {"EET", "EET"}, // Africa/Cairo + "Egypt Standard Time": {"EET", "EEST"}, // Africa/Cairo "Morocco Standard Time": {"WET", "WEST"}, // Africa/Casablanca "South Africa Standard Time": {"SAST", "SAST"}, // Africa/Johannesburg "W. Central Africa Standard Time": {"WAT", "WAT"}, // Africa/Lagos "E. Africa Standard Time": {"EAT", "EAT"}, // Africa/Nairobi + "Libya Standard Time": {"EET", "EET"}, // Africa/Tripoli "Namibia Standard Time": {"WAT", "WAST"}, // Africa/Windhoek "Alaskan Standard Time": {"AKST", "AKDT"}, // America/Anchorage "Paraguay Standard Time": {"PYT", "PYST"}, // America/Asuncion - "Bahia Standard Time": {"BRT", "BRST"}, // America/Bahia + "Bahia Standard Time": {"BRT", "BRT"}, // America/Bahia "SA Pacific Standard Time": {"COT", "COT"}, // America/Bogota "Argentina Standard Time": {"ART", "ART"}, // America/Buenos_Aires "Venezuela Standard Time": {"VET", "VET"}, // America/Caracas @@ -63,7 +64,6 @@ var abbrs = map[string]abbr{ "Nepal Standard Time": {"NPT", "NPT"}, // Asia/Katmandu "North Asia Standard Time": {"KRAT", "KRAT"}, // Asia/Krasnoyarsk "Magadan Standard Time": {"MAGT", "MAGT"}, // Asia/Magadan - "E. Europe Standard Time": {"EET", "EEST"}, // Asia/Nicosia "N. Central Asia Standard Time": {"NOVT", "NOVT"}, // Asia/Novosibirsk "Myanmar Standard Time": {"MMT", "MMT"}, // Asia/Rangoon "Arab Standard Time": {"AST", "AST"}, // Asia/Riyadh @@ -105,11 +105,12 @@ var abbrs = map[string]abbr{ "Romance Standard Time": {"CET", "CEST"}, // Europe/Paris "Central European Standard Time": {"CET", "CEST"}, // Europe/Warsaw "Mauritius Standard Time": {"MUT", "MUT"}, // Indian/Mauritius - "Samoa Standard Time": {"WST", "WST"}, // Pacific/Apia + "Samoa Standard Time": {"WST", "WSDT"}, // Pacific/Apia "New Zealand Standard Time": {"NZST", "NZDT"}, // Pacific/Auckland - "Fiji Standard Time": {"FJT", "FJT"}, // Pacific/Fiji + "Fiji Standard Time": {"FJT", "FJST"}, // Pacific/Fiji "Central Pacific Standard Time": {"SBT", "SBT"}, // Pacific/Guadalcanal "Hawaiian Standard Time": {"HST", "HST"}, // Pacific/Honolulu + "Line Islands Standard Time": {"LINT", "LINT"}, // Pacific/Kiritimati "West Pacific Standard Time": {"PGT", "PGT"}, // Pacific/Port_Moresby "Tonga Standard Time": {"TOT", "TOT"}, // Pacific/Tongatapu } diff --git a/src/pkg/time/zoneinfo_windows.go b/src/pkg/time/zoneinfo_windows.go index 6046743e67..02d8e0edcc 100644 --- a/src/pkg/time/zoneinfo_windows.go +++ b/src/pkg/time/zoneinfo_windows.go @@ -11,6 +11,8 @@ import ( "unsafe" ) +//go:generate go run genzabbrs.go -output zoneinfo_abbrs_windows.go + // TODO(rsc): Fall back to copy of zoneinfo files. // BUG(brainman,rsc): On Windows, the operating system does not provide complete