Source file
src/time/tzdata/generate_zipdata.go
1
2
3
4
5
6
7
8
9 package main
10
11 import (
12 "bufio"
13 "fmt"
14 "os"
15 "strconv"
16 )
17
18
19
20
21 const header = `// Copyright 2020 The Go Authors. All rights reserved.
22 // Use of this source code is governed by a BSD-style
23 // license that can be found in the LICENSE file.
24
25 ` + `// Code generated by generate_zipdata. DO NOT EDIT.
26
27 // This file contains an embedded zip archive that contains time zone
28 // files compiled using the code and data maintained as part of the
29 // IANA Time Zone Database.
30 // The IANA asserts that the data is in the public domain.
31
32 // For more information, see
33 // https://www.iana.org/time-zones
34 // ftp://ftp.iana.org/tz/code/tz-link.htm
35 // http://tools.ietf.org/html/rfc6557
36
37 package tzdata
38
39 const zipdata = `
40
41 func main() {
42
43 data, err := os.ReadFile("../../../lib/time/zoneinfo.zip")
44 if err != nil {
45 die("cannot find zoneinfo.zip file: %v", err)
46 }
47
48 of, err := os.Create("zipdata.go")
49 if err != nil {
50 die("%v", err)
51 }
52
53 buf := bufio.NewWriter(of)
54 buf.WriteString(header)
55
56 ds := string(data)
57 i := 0
58 const chunk = 60
59 for ; i+chunk < len(data); i += chunk {
60 if i > 0 {
61 buf.WriteRune('\t')
62 }
63 fmt.Fprintf(buf, "%s +\n", strconv.Quote(ds[i:i+chunk]))
64 }
65 fmt.Fprintf(buf, "\t%s\n", strconv.Quote(ds[i:]))
66
67 if err := buf.Flush(); err != nil {
68 die("error writing to zipdata.go: %v", err)
69 }
70 if err := of.Close(); err != nil {
71 die("error closing zipdata.go: %v", err)
72 }
73 }
74
75 func die(format string, args ...interface{}) {
76 fmt.Fprintf(os.Stderr, format+"\n", args...)
77 os.Exit(1)
78 }
79
View as plain text