]> Cypherpunks repositories - gostls13.git/commitdiff
time: use names for beginning and end of zone transition times
authorIan Lance Taylor <iant@golang.org>
Sat, 1 Feb 2014 01:22:10 +0000 (17:22 -0800)
committerIan Lance Taylor <iant@golang.org>
Sat, 1 Feb 2014 01:22:10 +0000 (17:22 -0800)
No functional changes, just more readable code.

LGTM=r
R=golang-codereviews, gobot, r
CC=golang-codereviews
https://golang.org/cl/59240043

src/pkg/time/zoneinfo.go
src/pkg/time/zoneinfo_plan9.go
src/pkg/time/zoneinfo_read.go
src/pkg/time/zoneinfo_windows.go

index a45757031bc65e37fc7a0906464d6481d6a194d0..c8e53a27cf02328ffc8a16909e95dcbea219765d 100644 (file)
@@ -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 {
index 0e8f3811bedc1d4d1919e9c717651dfffa5cb881..4bb0cb3909683536e22e8b6c93ab986f079b0b3c 100644 (file)
@@ -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
                        }
index 7714aa9f583ae4507740d77701c4203e88841b69..4bb4bf665cc23675fd6c39e56e3d1710418cd379 100644 (file)
@@ -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
                        }
index 7e4d146d89eed68f4bfcdd1984cafde87471f2ed..377a892153858016b1a81dec8a7c9f3648516a37 100644 (file)
@@ -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