aboutsummaryrefslogtreecommitdiff
path: root/src/time/format.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2016-10-17 15:47:18 -0400
committerRuss Cox <rsc@golang.org>2016-10-18 12:42:46 +0000
commit5fbf35dc3fadd29785739fcec061d42157ea7861 (patch)
treec97c7226b3f9f63d2000753aec38de72521dc3d6 /src/time/format.go
parent79c036238d83c8fceb49aa4bab4d6dade1c321f6 (diff)
downloadgo-5fbf35dc3fadd29785739fcec061d42157ea7861.tar.gz
go-5fbf35dc3fadd29785739fcec061d42157ea7861.zip
time: be consistent about representation of UTC location in Time struct
In the zero Time, the (not user visible) nil *Location indicates UTC. In the result of t.UTC() and other ways to create times in specific zones, UTC is indicated by a non-nil *Location, specifically &utcLoc. This creates a representation ambiguity exposed by comparison with == or reflect.DeepEqual or the like. Change time.Time representation to use only nil, never &utcLoc, to represent UTC. This eliminates the ambiguity. Fixes #15716. Change-Id: I7dcc2c20ce6b073e1daae323d3e49d17d1d52802 Reviewed-on: https://go-review.googlesource.com/31144 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/time/format.go')
-rw-r--r--src/time/format.go8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/time/format.go b/src/time/format.go
index ea95f0be44..0ad3cf64e4 100644
--- a/src/time/format.go
+++ b/src/time/format.go
@@ -1021,12 +1021,12 @@ func parse(layout, value string, defaultLocation, local *Location) (Time, error)
// If that zone was in effect at the given time, use it.
name, offset, _, _, _ := local.lookup(t.sec + internalToUnix)
if offset == zoneOffset && (zoneName == "" || name == zoneName) {
- t.loc = local
+ t.setLoc(local)
return t, nil
}
// Otherwise create fake zone to record offset.
- t.loc = FixedZone(zoneName, zoneOffset)
+ t.setLoc(FixedZone(zoneName, zoneOffset))
return t, nil
}
@@ -1037,7 +1037,7 @@ func parse(layout, value string, defaultLocation, local *Location) (Time, error)
offset, _, ok := local.lookupName(zoneName, t.sec+internalToUnix)
if ok {
t.sec -= int64(offset)
- t.loc = local
+ t.setLoc(local)
return t, nil
}
@@ -1046,7 +1046,7 @@ func parse(layout, value string, defaultLocation, local *Location) (Time, error)
offset, _ = atoi(zoneName[3:]) // Guaranteed OK by parseGMT.
offset *= 3600
}
- t.loc = FixedZone(zoneName, offset)
+ t.setLoc(FixedZone(zoneName, offset))
return t, nil
}