Source File
tzdata.go
Belonging Package
time/tzdata
// Copyright 2020 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.
// Package tzdata provides an embedded copy of the timezone database.
// If this package is imported anywhere in the program, then if
// the time package cannot find tzdata files on the system,
// it will use this embedded information.
//
// Importing this package will increase the size of a program by about
// 450 KB.
//
// This package should normally be imported by a program's main package,
// not by a library. Libraries normally shouldn't decide whether to
// include the timezone database in a program.
//
// This package will be automatically imported if you build with
// -tags timetzdata.
package tzdata
// The test for this package is time/tzdata_test.go.
import (
_ // for go:linkname
)
// registerLoadFromEmbeddedTZData is defined in package time.
//
//go:linkname registerLoadFromEmbeddedTZData time.registerLoadFromEmbeddedTZData
func registerLoadFromEmbeddedTZData(func(string) (string, error))
func init() {
registerLoadFromEmbeddedTZData(loadFromEmbeddedTZData)
}
// get4s returns the little-endian 32-bit value at the start of s.
func get4s( string) int {
if len() < 4 {
return 0
}
return int([0]) | int([1])<<8 | int([2])<<16 | int([3])<<24
}
// get2s returns the little-endian 16-bit value at the start of s.
func get2s( string) int {
if len() < 2 {
return 0
}
return int([0]) | int([1])<<8
}
// loadFromEmbeddedTZData returns the contents of the file with the given
// name in an uncompressed zip file, where the contents of the file can
// be found in embeddedTzdata.
// This is similar to time.loadTzinfoFromZip.
func loadFromEmbeddedTZData( string) (string, error) {
const (
= 0x06054b50
= 0x02014b50
= 22
= 30
= 0x04034b50
)
// zipdata is provided by zzipdata.go,
// which is generated by cmd/dist during make.bash.
:= zipdata
:= len() -
:= get2s([+10:])
= get4s([+16:])
for := 0; < ; ++ {
// See time.loadTzinfoFromZip for zip entry layout.
if get4s([:]) != {
break
}
:= get2s([+10:])
:= get4s([+24:])
:= get2s([+28:])
:= get2s([+30:])
:= get2s([+32:])
:= get4s([+42:])
:= [+46 : +46+]
+= 46 + + +
if != {
continue
}
if != 0 {
return "", errors.New("unsupported compression for " + + " in embedded tzdata")
}
// See time.loadTzinfoFromZip for zip per-file header layout.
=
if get4s([:]) != ||
get2s([+8:]) != ||
get2s([+26:]) != ||
[+30:+30+] != {
return "", errors.New("corrupt embedded tzdata")
}
= get2s([+28:])
+= 30 + +
return [ : +], nil
}
return "", syscall.ENOENT
}
The pages are generated with Golds v0.7.0-preview. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |