summaryrefslogtreecommitdiffstats
path: root/lib/time
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-16 19:25:22 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-16 19:25:22 +0000
commitf6ad4dcef54c5ce997a4bad5a6d86de229015700 (patch)
tree7cfa4e31ace5c2bd95c72b154d15af494b2bcbef /lib/time
parentInitial commit. (diff)
downloadgolang-1.22-f6ad4dcef54c5ce997a4bad5a6d86de229015700.tar.xz
golang-1.22-f6ad4dcef54c5ce997a4bad5a6d86de229015700.zip
Adding upstream version 1.22.1.upstream/1.22.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'lib/time')
-rw-r--r--lib/time/README10
-rw-r--r--lib/time/mkzip.go94
-rwxr-xr-xlib/time/update.bash86
-rw-r--r--lib/time/zoneinfo.zipbin0 -> 401728 bytes
4 files changed, 190 insertions, 0 deletions
diff --git a/lib/time/README b/lib/time/README
new file mode 100644
index 0000000..0de06df
--- /dev/null
+++ b/lib/time/README
@@ -0,0 +1,10 @@
+The zoneinfo.zip archive contains time zone files compiled using
+the code and data maintained as part of the IANA Time Zone Database.
+The IANA asserts that the database is in the public domain.
+
+For more information, see
+https://www.iana.org/time-zones
+ftp://ftp.iana.org/tz/code/tz-link.html
+https://datatracker.ietf.org/doc/html/rfc6557
+
+To rebuild the archive, read and run update.bash.
diff --git a/lib/time/mkzip.go b/lib/time/mkzip.go
new file mode 100644
index 0000000..3920b11
--- /dev/null
+++ b/lib/time/mkzip.go
@@ -0,0 +1,94 @@
+// Copyright 2022 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.
+
+//go:build ignore
+
+// Mkzip writes a zoneinfo.zip with the content of the current directory
+// and its subdirectories, with no compression, suitable for package time.
+//
+// Usage:
+//
+// go run ../../mkzip.go ../../zoneinfo.zip
+//
+// We use this program instead of 'zip -0 -r ../../zoneinfo.zip *' to get
+// a reproducible generator that does not depend on which version of the
+// external zip tool is used or the ordering of file names in a directory
+// or the current time.
+package main
+
+import (
+ "archive/zip"
+ "bytes"
+ "flag"
+ "fmt"
+ "hash/crc32"
+ "io/fs"
+ "log"
+ "os"
+ "path/filepath"
+ "strings"
+)
+
+func usage() {
+ fmt.Fprintf(os.Stderr, "usage: go run mkzip.go ../../zoneinfo.zip\n")
+ os.Exit(2)
+}
+
+func main() {
+ log.SetPrefix("mkzip: ")
+ log.SetFlags(0)
+ flag.Usage = usage
+ flag.Parse()
+ args := flag.Args()
+ if len(args) != 1 || !strings.HasSuffix(args[0], ".zip") {
+ usage()
+ }
+
+ var zb bytes.Buffer
+ zw := zip.NewWriter(&zb)
+ seen := make(map[string]bool)
+ err := filepath.WalkDir(".", func(path string, d fs.DirEntry, err error) error {
+ if d.IsDir() {
+ return nil
+ }
+ data, err := os.ReadFile(path)
+ if err != nil {
+ log.Fatal(err)
+ }
+ if strings.HasSuffix(path, ".zip") {
+ log.Fatalf("unexpected file during walk: %s", path)
+ }
+ name := filepath.ToSlash(path)
+ w, err := zw.CreateRaw(&zip.FileHeader{
+ Name: name,
+ Method: zip.Store,
+ CompressedSize64: uint64(len(data)),
+ UncompressedSize64: uint64(len(data)),
+ CRC32: crc32.ChecksumIEEE(data),
+ })
+ if err != nil {
+ log.Fatal(err)
+ }
+ if _, err := w.Write(data); err != nil {
+ log.Fatal(err)
+ }
+ seen[name] = true
+ return nil
+ })
+ if err != nil {
+ log.Fatal(err)
+ }
+ if err := zw.Close(); err != nil {
+ log.Fatal(err)
+ }
+ if len(seen) == 0 {
+ log.Fatalf("did not find any files to add")
+ }
+ if !seen["US/Eastern"] {
+ log.Fatalf("did not find US/Eastern to add")
+ }
+ if err := os.WriteFile(args[0], zb.Bytes(), 0666); err != nil {
+ log.Fatal(err)
+ }
+}
diff --git a/lib/time/update.bash b/lib/time/update.bash
new file mode 100755
index 0000000..e728500
--- /dev/null
+++ b/lib/time/update.bash
@@ -0,0 +1,86 @@
+#!/bin/bash
+# Copyright 2012 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.
+
+# This script rebuilds the time zone files using files
+# downloaded from the ICANN/IANA distribution.
+#
+# To prepare an update for a new Go release,
+# consult https://www.iana.org/time-zones for the latest versions,
+# update CODE and DATA below, and then run
+#
+# ./update.bash -commit
+#
+# That will prepare the files and create the commit.
+#
+# To review such a commit (as the reviewer), use:
+#
+# git codereview change NNNNNN # CL number
+# cd lib/time
+# ./update.bash
+#
+# If it prints "No updates needed.", then the generated files
+# in the CL match the update.bash in the CL.
+
+# Versions to use.
+CODE=2023d
+DATA=2023d
+
+set -e
+
+cd $(dirname $0)
+rm -rf work
+mkdir work
+go build -o work/mkzip mkzip.go # build now for correct paths in build errors
+cd work
+mkdir zoneinfo
+curl -sS -L -O https://www.iana.org/time-zones/repository/releases/tzcode$CODE.tar.gz
+curl -sS -L -O https://www.iana.org/time-zones/repository/releases/tzdata$DATA.tar.gz
+tar xzf tzcode$CODE.tar.gz
+tar xzf tzdata$DATA.tar.gz
+
+if ! make CFLAGS=-DSTD_INSPIRED AWK=awk TZDIR=zoneinfo posix_only >make.out 2>&1; then
+ cat make.out
+ exit 2
+fi
+
+cd zoneinfo
+../mkzip ../../zoneinfo.zip
+cd ../..
+
+files="update.bash zoneinfo.zip"
+modified=true
+if git diff --quiet $files; then
+ modified=false
+fi
+
+if [ "$1" = "-work" ]; then
+ echo Left workspace behind in work/.
+ shift
+else
+ rm -rf work
+fi
+
+if ! $modified; then
+ echo No updates needed.
+ exit 0
+fi
+
+echo Updated for $CODE/$DATA: $files
+
+commitmsg="lib/time: update to $CODE/$DATA
+
+Commit generated by update.bash.
+
+For #22487.
+"
+
+if [ "$1" = "-commit" ]; then
+ echo "Creating commit. Run 'git reset HEAD^' to undo commit."
+ echo
+ git commit -m "$commitmsg" $files
+ echo
+ git log -n1 --stat
+ echo
+fi
diff --git a/lib/time/zoneinfo.zip b/lib/time/zoneinfo.zip
new file mode 100644
index 0000000..7cf689f
--- /dev/null
+++ b/lib/time/zoneinfo.zip
Binary files differ