From 51021cc83f54964aa5e6a71cdf2206ae169acbb8 Mon Sep 17 00:00:00 2001 From: Patrick Mezard Date: Tue, 12 May 2015 08:19:00 +0200 Subject: [PATCH] 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 Reviewed-by: Brad Fitzpatrick --- src/time/export_windows_test.go | 4 ++++ src/time/zoneinfo_windows.go | 2 +- src/time/zoneinfo_windows_test.go | 25 +++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/time/export_windows_test.go b/src/time/export_windows_test.go index 7e689b829f..6fd4509137 100644 --- a/src/time/export_windows_test.go +++ b/src/time/export_windows_test.go @@ -8,3 +8,7 @@ func ForceAusForTesting() { ResetLocalOnceForTest() localOnce.Do(initAusTestingZone) } + +func ToEnglishName(stdname, dstname string) (string, error) { + return toEnglishName(stdname, dstname) +} diff --git a/src/time/zoneinfo_windows.go b/src/time/zoneinfo_windows.go index 9f987ab302..d04ebec614 100644 --- a/src/time/zoneinfo_windows.go +++ b/src/time/zoneinfo_windows.go @@ -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 } diff --git a/src/time/zoneinfo_windows_test.go b/src/time/zoneinfo_windows_test.go index 9db81b7cfd..5f1141d3ca 100644 --- a/src/time/zoneinfo_windows_test.go +++ b/src/time/zoneinfo_windows_test.go @@ -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) + } +} -- 2.48.1