From: Ian Lance Taylor Date: Sat, 1 Feb 2014 01:22:10 +0000 (-0800) Subject: time: use names for beginning and end of zone transition times X-Git-Tag: go1.3beta1~832 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=fabd261fe2fe0adf5f79b9bb1069df0a93575ae9;p=gostls13.git time: use names for beginning and end of zone transition times No functional changes, just more readable code. LGTM=r R=golang-codereviews, gobot, r CC=golang-codereviews https://golang.org/cl/59240043 --- diff --git a/src/pkg/time/zoneinfo.go b/src/pkg/time/zoneinfo.go index a45757031b..c8e53a27cf 100644 --- a/src/pkg/time/zoneinfo.go +++ b/src/pkg/time/zoneinfo.go @@ -45,6 +45,13 @@ type zoneTrans struct { isstd, isutc bool // ignored - no idea what these mean } +// alpha and omega are the beginning and end of time for zone +// transitions. +const ( + alpha = -1 << 63 // math.MinInt64 + omega = 1<<63 - 1 // math.MaxInt64 +) + // UTC represents Universal Coordinated Time (UTC). var UTC *Location = &utcLoc @@ -83,9 +90,9 @@ func FixedZone(name string, offset int) *Location { l := &Location{ name: name, zone: []zone{{name, offset, false}}, - tx: []zoneTrans{{-1 << 63, 0, false, false}}, - cacheStart: -1 << 63, - cacheEnd: 1<<63 - 1, + tx: []zoneTrans{{alpha, 0, false, false}}, + cacheStart: alpha, + cacheEnd: omega, } l.cacheZone = &l.zone[0] return l @@ -105,8 +112,8 @@ func (l *Location) lookup(sec int64) (name string, offset int, isDST bool, start name = "UTC" offset = 0 isDST = false - start = -1 << 63 - end = 1<<63 - 1 + start = alpha + end = omega return } @@ -124,11 +131,11 @@ func (l *Location) lookup(sec int64) (name string, offset int, isDST bool, start name = zone.name offset = zone.offset isDST = zone.isDST - start = -1 << 63 + start = alpha if len(l.tx) > 0 { end = l.tx[0].when } else { - end = 1<<63 - 1 + end = omega } return } @@ -136,7 +143,7 @@ func (l *Location) lookup(sec int64) (name string, offset int, isDST bool, start // Binary search for entry with largest time <= sec. // Not using sort.Search to avoid dependencies. tx := l.tx - end = 1<<63 - 1 + end = omega lo := 0 hi := len(tx) for hi-lo > 1 { diff --git a/src/pkg/time/zoneinfo_plan9.go b/src/pkg/time/zoneinfo_plan9.go index 0e8f3811be..4bb0cb3909 100644 --- a/src/pkg/time/zoneinfo_plan9.go +++ b/src/pkg/time/zoneinfo_plan9.go @@ -100,7 +100,7 @@ func loadZoneDataPlan9(s string) (l *Location, err error) { for i := range tx { if tx[i].when <= sec && (i+1 == len(tx) || sec < tx[i+1].when) { l.cacheStart = tx[i].when - l.cacheEnd = 1<<63 - 1 + l.cacheEnd = omega if i+1 < len(tx) { l.cacheEnd = tx[i+1].when } diff --git a/src/pkg/time/zoneinfo_read.go b/src/pkg/time/zoneinfo_read.go index 7714aa9f58..4bb4bf665c 100644 --- a/src/pkg/time/zoneinfo_read.go +++ b/src/pkg/time/zoneinfo_read.go @@ -173,7 +173,7 @@ func loadZoneData(bytes []byte) (l *Location, err error) { if len(tx) == 0 { // Build fake transition to cover all time. // This happens in fixed locations like "Etc/GMT0". - tx = append(tx, zoneTrans{when: -1 << 63, index: 0}) + tx = append(tx, zoneTrans{when: alpha, index: 0}) } // Committed to succeed. @@ -185,7 +185,7 @@ func loadZoneData(bytes []byte) (l *Location, err error) { for i := range tx { if tx[i].when <= sec && (i+1 == len(tx) || sec < tx[i+1].when) { l.cacheStart = tx[i].when - l.cacheEnd = 1<<63 - 1 + l.cacheEnd = omega if i+1 < len(tx) { l.cacheEnd = tx[i+1].when } diff --git a/src/pkg/time/zoneinfo_windows.go b/src/pkg/time/zoneinfo_windows.go index 7e4d146d89..377a892153 100644 --- a/src/pkg/time/zoneinfo_windows.go +++ b/src/pkg/time/zoneinfo_windows.go @@ -165,8 +165,8 @@ func initLocalFromTZI(i *syscall.Timezoneinformation) { if nzone == 1 { // No daylight savings. std.offset = -int(i.Bias) * 60 - l.cacheStart = -1 << 63 - l.cacheEnd = 1<<63 - 1 + l.cacheStart = alpha + l.cacheEnd = omega l.cacheZone = std l.tx = make([]zoneTrans, 1) l.tx[0].when = l.cacheStart