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.
17 // header is put at the start of the generated file.
18 // The string addition avoids this file (generate_zipdata.go) from
19 // matching the "generated file" regexp.
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.html
34 // https://datatracker.ietf.org/doc/html/rfc6557
41 // We should be run in the $GOROOT/src/time/tzdata directory.
42 data, err := os.ReadFile("../../../lib/time/zoneinfo.zip")
44 die("cannot find zoneinfo.zip file: %v", err)
47 of, err := os.Create("zipdata.go")
52 buf := bufio.NewWriter(of)
53 buf.WriteString(header)
58 for ; i+chunk < len(data); i += chunk {
62 fmt.Fprintf(buf, "%s +\n", strconv.Quote(ds[i:i+chunk]))
64 fmt.Fprintf(buf, "\t%s\n", strconv.Quote(ds[i:]))
66 if err := buf.Flush(); err != nil {
67 die("error writing to zipdata.go: %v", err)
69 if err := of.Close(); err != nil {
70 die("error closing zipdata.go: %v", err)
74 func die(format string, args ...any) {
75 fmt.Fprintf(os.Stderr, format+"\n", args...)