Source File
zoneinfo_read.go
Belonging Package
time
package time
import (
)
func ( func(string) (string, error)) {
loadFromEmbeddedTZData =
}
var loadFromEmbeddedTZData func(zipname string) (string, error)
const maxFileSize = 10 << 20
type fileSizeError string
func ( fileSizeError) () string {
return "time: file " + string() + " is too large"
}
const (
seekStart = 0
seekCurrent = 1
seekEnd = 2
)
type dataIO struct {
p []byte
error bool
}
func ( *dataIO) ( int) []byte {
if len(.p) < {
.p = nil
.error = true
return nil
}
:= .p[0:]
.p = .p[:]
return
}
func ( *dataIO) () ( uint32, bool) {
:= .read(4)
if len() < 4 {
.error = true
return 0, false
}
return uint32([3]) | uint32([2])<<8 | uint32([1])<<16 | uint32([0])<<24, true
}
func ( *dataIO) () ( uint64, bool) {
, := .big4()
, := .big4()
if ! || ! {
.error = true
return 0, false
}
return (uint64() << 32) | uint64(), true
}
func ( *dataIO) () ( byte, bool) {
:= .read(1)
if len() < 1 {
.error = true
return 0, false
}
return [0], true
}
:= false
:= []*4 +
[] +
[]*6 +
[] +
[]*8 +
[] +
:= .read([])
:= .read([])
.read([] * ( + 4))
:= .read([])
:= []
return nil, badData
}
:= make([]zone, )
for := range {
var bool
var uint32
if , = .big4(); ! {
return nil, badData
}
if uint32(int()) != {
return nil, badData
}
[].offset = int(int32())
var byte
if , = .byte(); ! {
return nil, badData
}
[].isDST = != 0
if , = .byte(); ! || int() >= len() {
return nil, badData
}
[].name = byteString([:])
[].name = [4:]
}
}
}
:= make([]zoneTrans, [])
for := range {
var int64
if ! {
if , := .big4(); ! {
return nil, badData
} else {
= int64(int32())
}
} else {
if , := .big8(); ! {
return nil, badData
} else {
= int64()
}
}
[].when =
if int([]) >= len() {
return nil, badData
}
[].index = []
if < len() {
[].isstd = [] != 0
}
if < len() {
[].isutc = [] != 0
}
}
if , , , , := tzset(.extend, .cacheEnd, ); {
.cacheStart =
func (, string) ([]byte, error) {
, := open()
if != nil {
return nil,
}
defer closefd()
const (
= 0x06054b50
= 0x02014b50
= 22
= 30
= 0x04034b50
)
:= make([]byte, )
if := preadn(, , -); != nil || get4() != {
return nil, errors.New("corrupt zip file " + )
}
:= get2([10:])
:= get4([12:])
:= get4([16:])
= make([]byte, )
if := preadn(, , ); != nil {
return nil, errors.New("corrupt zip file " + )
}
= make([]byte, +)
if := preadn(, , ); != nil ||
get4() != ||
get2([8:]) != ||
get2([26:]) != ||
string([30:30+]) != {
return nil, errors.New("corrupt zip file " + )
}
= get2([28:])
= make([]byte, )
if := preadn(, , +30++); != nil {
return nil, errors.New("corrupt zip file " + )
}
return , nil
}
return nil, syscall.ENOENT
}
var loadTzinfoFromTzdata func(file, name string) ([]byte, error)
func ( string, string) ([]byte, error) {
if len() >= 6 && [len()-6:] == "tzdata" {
return loadTzinfoFromTzdata(, )
}
return loadTzinfoFromDirOrZip(, )
}
func ( string, []string) ( *Location, error) {
for , := range {
var , = loadTzinfo(, )
if == nil {
if , = LoadLocationFromTZData(, ); == nil {
return , nil
}
}
if == nil && != syscall.ENOENT {
=
}
}
if loadFromEmbeddedTZData != nil {
, := loadFromEmbeddedTZData()
if == nil {
if , = LoadLocationFromTZData(, []byte()); == nil {
return , nil
}
}
if == nil && != syscall.ENOENT {
=
}
}
if != nil {
return nil,
}
return nil, errors.New("unknown time zone " + )
}
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin 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 @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |