1 // Copyright 2020 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.
7 // This program generates zipdata.go from $GOROOT/lib/time/zoneinfo.zip.
20 const header = `// Copyright 2020 The Go Authors. All rights reserved.
21 // Use of this source code is governed by a BSD-style
22 // license that can be found in the LICENSE file.
24 // Code generated by generate_zipdata. DO NOT EDIT.
26 // This file contains an embedded zip archive that contains time zone
27 // files compiled using the code and data maintained as part of the
28 // IANA Time Zone Database.
29 // The IANA asserts that the data is in the public domain.
31 // For more information, see
32 // https://www.iana.org/time-zones
33 // ftp://ftp.iana.org/tz/code/tz-link.htm
34 // http://tools.ietf.org/html/rfc6557
41 // We should be run in the $GOROOT/src/time/tzdata directory.
42 data, err := ioutil.ReadFile("../../../lib/time/zoneinfo.zip")
44 if os.IsNotExist(err) {
45 // For convenience try $GOROOT as a backup.
46 data, err = ioutil.ReadFile(filepath.Join(runtime.GOROOT(), "lib", "time", "zoneinfo.zip"))
49 die("cannot find zoneinfo.zip file: %v", err)
53 of, err := os.Create("zipdata.go")
58 buf := bufio.NewWriter(of)
59 buf.WriteString(header)
64 for ; i+chunk < len(data); i += chunk {
68 fmt.Fprintf(buf, "%s +\n", strconv.Quote(ds[i:i+chunk]))
70 fmt.Fprintf(buf, "\t%s\n", strconv.Quote(ds[i:]))
72 if err := buf.Flush(); err != nil {
73 die("error writing to zipdata.go: %v", err)
75 if err := of.Close(); err != nil {
76 die("error closing zipdata.go: %v", err)
80 func die(format string, args ...interface{}) {
81 fmt.Fprintf(os.Stderr, format+"\n", args...)