Commit 51021cc8 authored by Patrick Mezard's avatar Patrick Mezard Committed by Brad Fitzpatrick

time: fix registry zone info lookup on Windows

registry.ReadSubKeyNames requires QUERY access right in addition to
ENUMERATE_SUB_KEYS.

This was making TestLocalZoneAbbr fail on Windows 7 in Paris/Madrid
timezone. It succeeded on Windows 8 because timezone name changed from
"Paris/Madrid" to "Romance Standard Time", the latter being matched by
an abbrs entry.

Change-Id: I791287ba9d1b3556246fa4e9e1604a1fbba1f5e6
Reviewed-on: https://go-review.googlesource.com/9809Reviewed-by: default avatarAlex Brainman <alex.brainman@gmail.com>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 71bf1820
...@@ -8,3 +8,7 @@ func ForceAusForTesting() { ...@@ -8,3 +8,7 @@ func ForceAusForTesting() {
ResetLocalOnceForTest() ResetLocalOnceForTest()
localOnce.Do(initAusTestingZone) localOnce.Do(initAusTestingZone)
} }
func ToEnglishName(stdname, dstname string) (string, error) {
return toEnglishName(stdname, dstname)
}
...@@ -49,7 +49,7 @@ func matchZoneKey(zones registry.Key, kname string, stdname, dstname string) (ma ...@@ -49,7 +49,7 @@ func matchZoneKey(zones registry.Key, kname string, stdname, dstname string) (ma
// toEnglishName searches the registry for an English name of a time zone // toEnglishName searches the registry for an English name of a time zone
// whose zone names are stdname and dstname and returns the English name. // whose zone names are stdname and dstname and returns the English name.
func toEnglishName(stdname, dstname string) (string, error) { func toEnglishName(stdname, dstname string) (string, error) {
k, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones`, registry.ENUMERATE_SUB_KEYS) k, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones`, registry.ENUMERATE_SUB_KEYS|registry.QUERY_VALUE)
if err != nil { if err != nil {
return "", err return "", err
} }
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
package time_test package time_test
import ( import (
"internal/syscall/windows/registry"
"testing" "testing"
. "time" . "time"
) )
...@@ -33,3 +34,27 @@ func TestAusZoneAbbr(t *testing.T) { ...@@ -33,3 +34,27 @@ func TestAusZoneAbbr(t *testing.T) {
defer ForceUSPacificForTesting() defer ForceUSPacificForTesting()
testZoneAbbr(t) testZoneAbbr(t)
} }
func TestToEnglishName(t *testing.T) {
const want = "Central Europe Standard Time"
k, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones\`+want, registry.READ)
if err != nil {
t.Fatalf("cannot open CEST time zone information from registry: %s", err)
}
defer k.Close()
std, _, err := k.GetStringValue("Std")
if err != nil {
t.Fatalf("cannot read CEST Std registry key: %s", err)
}
dlt, _, err := k.GetStringValue("Dlt")
if err != nil {
t.Fatalf("cannot read CEST Dlt registry key: %s", err)
}
name, err := ToEnglishName(std, dlt)
if err != nil {
t.Fatalf("toEnglishName failed: %s", err)
}
if name != want {
t.Fatalf("english name: %q, want: %q", name, want)
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment