summaryrefslogtreecommitdiff
path: root/src/pkg/time/zoneinfo.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/pkg/time/zoneinfo.go')
-rw-r--r--src/pkg/time/zoneinfo.go39
1 files changed, 31 insertions, 8 deletions
diff --git a/src/pkg/time/zoneinfo.go b/src/pkg/time/zoneinfo.go
index 3c5774404..c44477f47 100644
--- a/src/pkg/time/zoneinfo.go
+++ b/src/pkg/time/zoneinfo.go
@@ -123,35 +123,58 @@ func (l *Location) lookup(sec int64) (name string, offset int, isDST bool, start
// Not using sort.Search to avoid dependencies.
tx := l.tx
end = 1<<63 - 1
- for len(tx) > 1 {
- m := len(tx) / 2
+ lo := 0
+ hi := len(tx)
+ for hi-lo > 1 {
+ m := lo + (hi-lo)/2
lim := tx[m].when
if sec < lim {
end = lim
- tx = tx[0:m]
+ hi = m
} else {
- tx = tx[m:]
+ lo = m
}
}
- zone := &l.zone[tx[0].index]
+ zone := &l.zone[tx[lo].index]
name = zone.name
offset = zone.offset
isDST = zone.isDST
- start = tx[0].when
+ start = tx[lo].when
// end = maintained during the search
return
}
// lookupName returns information about the time zone with
-// the given name (such as "EST").
-func (l *Location) lookupName(name string) (offset int, isDST bool, ok bool) {
+// the given name (such as "EST") at the given pseudo-Unix time
+// (what the given time of day would be in UTC).
+func (l *Location) lookupName(name string, unix int64) (offset int, isDST bool, ok bool) {
l = l.get()
+
+ // First try for a zone with the right name that was actually
+ // in effect at the given time. (In Sydney, Australia, both standard
+ // and daylight-savings time are abbreviated "EST". Using the
+ // offset helps us pick the right one for the given time.
+ // It's not perfect: during the backward transition we might pick
+ // either one.)
+ for i := range l.zone {
+ zone := &l.zone[i]
+ if zone.name == name {
+ nam, offset, isDST, _, _ := l.lookup(unix - int64(zone.offset))
+ if nam == zone.name {
+ return offset, isDST, true
+ }
+ }
+ }
+
+ // Otherwise fall back to an ordinary name match.
for i := range l.zone {
zone := &l.zone[i]
if zone.name == name {
return zone.offset, zone.isDST, true
}
}
+
+ // Otherwise, give up.
return
}