summaryrefslogtreecommitdiff
path: root/src/pkg/time/zoneinfo_windows.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2011-08-26 15:15:23 -0400
committerRuss Cox <rsc@golang.org>2011-08-26 15:15:23 -0400
commitdfa9d4e7565c14e5cc76d66c515d0d557a205975 (patch)
tree393d35a089d01181b1527bc3b9d1bfcd71aae4e6 /src/pkg/time/zoneinfo_windows.go
parent8697f59abdc9974d362a8359da2e8c928cc6d73e (diff)
downloadgo-dfa9d4e7565c14e5cc76d66c515d0d557a205975.tar.gz
time: fix zone during windows test
Factor out sleep interrupt. Fixes issue 1109. R=alex.brainman, go.peter.90, mattn.jp CC=golang-dev http://codereview.appspot.com/4968041
Diffstat (limited to 'src/pkg/time/zoneinfo_windows.go')
-rw-r--r--src/pkg/time/zoneinfo_windows.go44
1 files changed, 43 insertions, 1 deletions
diff --git a/src/pkg/time/zoneinfo_windows.go b/src/pkg/time/zoneinfo_windows.go
index fabc00601..ab3e7df59 100644
--- a/src/pkg/time/zoneinfo_windows.go
+++ b/src/pkg/time/zoneinfo_windows.go
@@ -27,9 +27,30 @@ type zone struct {
prev *zone
}
+// BUG(rsc): On Windows, time zone abbreviations are unavailable.
+// This package constructs them using the capital letters from a longer
+// time zone description.
+
// Populate zone struct with Windows supplied information. Returns true, if data is valid.
func (z *zone) populate(bias, biasdelta int32, d *syscall.Systemtime, name []uint16) (dateisgood bool) {
- z.name = syscall.UTF16ToString(name)
+ // name is 'Pacific Standard Time' but we want 'PST'.
+ // Extract just capital letters. It's not perfect but the
+ // information we need is not available from the kernel.
+ // Because time zone abbreviations are not unique,
+ // Windows refuses to expose them.
+ //
+ // http://social.msdn.microsoft.com/Forums/eu/vclanguage/thread/a87e1d25-fb71-4fe0-ae9c-a9578c9753eb
+ // http://stackoverflow.com/questions/4195948/windows-time-zone-abbreviations-in-asp-net
+ short := make([]uint16, len(name))
+ w := 0
+ for _, c := range name {
+ if 'A' <= c && c <= 'Z' {
+ short[w] = c
+ w++
+ }
+ }
+ z.name = syscall.UTF16ToString(short[:w])
+
z.offset = int(bias)
z.year = int64(d.Year)
z.month = int(d.Month)
@@ -129,6 +150,10 @@ func setupZone() {
initError = os.NewSyscallError("GetTimeZoneInformation", e)
return
}
+ setupZoneFromTZI(&i)
+}
+
+func setupZoneFromTZI(i *syscall.Timezoneinformation) {
if !tz.std.populate(i.Bias, i.StandardBias, &i.StandardDate, i.StandardName[0:]) {
tz.disabled = true
tz.offsetIfDisabled = tz.std.offset
@@ -144,6 +169,23 @@ func setupZone() {
tz.januaryIsStd = tz.dst.cutoffSeconds(t.Year) < tz.std.cutoffSeconds(t.Year)
}
+var usPacific = syscall.Timezoneinformation{
+ Bias: 8 * 60,
+ StandardName: [32]uint16{
+ 'P', 'a', 'c', 'i', 'f', 'i', 'c', ' ', 'S', 't', 'a', 'n', 'd', 'a', 'r', 'd', ' ', 'T', 'i', 'm', 'e',
+ },
+ StandardDate: syscall.Systemtime{Month: 11, Day: 1, Hour: 2},
+ DaylightName: [32]uint16{
+ 'P', 'a', 'c', 'i', 'f', 'i', 'c', ' ', 'D', 'a', 'y', 'l', 'i', 'g', 'h', 't', ' ', 'T', 'i', 'm', 'e',
+ },
+ DaylightDate: syscall.Systemtime{Month: 3, Day: 2, Hour: 2},
+ DaylightBias: -60,
+}
+
+func setupTestingZone() {
+ setupZoneFromTZI(&usPacific)
+}
+
// Look up the correct time zone (daylight savings or not) for the given unix time, in the current location.
func lookupTimezone(sec int64) (zone string, offset int) {
onceSetupZone.Do(setupZone)