1
0
mirror of https://github.com/golang/go synced 2024-09-30 12:28:35 -06:00

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/9809
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Patrick Mezard 2015-05-12 08:19:00 +02:00 committed by Brad Fitzpatrick
parent 71bf182028
commit 51021cc83f
3 changed files with 30 additions and 1 deletions

View File

@ -8,3 +8,7 @@ func ForceAusForTesting() {
ResetLocalOnceForTest()
localOnce.Do(initAusTestingZone)
}
func ToEnglishName(stdname, dstname string) (string, error) {
return toEnglishName(stdname, dstname)
}

View File

@ -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
// whose zone names are stdname and dstname and returns the English name.
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 {
return "", err
}

View File

@ -5,6 +5,7 @@
package time_test
import (
"internal/syscall/windows/registry"
"testing"
. "time"
)
@ -33,3 +34,27 @@ func TestAusZoneAbbr(t *testing.T) {
defer ForceUSPacificForTesting()
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)
}
}