]> Cypherpunks repositories - gostls13.git/commitdiff
time: fix registry zone info lookup on Windows
authorPatrick Mezard <patrick@mezard.eu>
Tue, 12 May 2015 06:19:00 +0000 (08:19 +0200)
committerBrad Fitzpatrick <bradfitz@golang.org>
Tue, 12 May 2015 14:28:40 +0000 (14:28 +0000)
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>
src/time/export_windows_test.go
src/time/zoneinfo_windows.go
src/time/zoneinfo_windows_test.go

index 7e689b829fa554697e931e3d958375674ed84bec..6fd45091379ef84d7825a0096849cceb2086ef01 100644 (file)
@@ -8,3 +8,7 @@ func ForceAusForTesting() {
        ResetLocalOnceForTest()
        localOnce.Do(initAusTestingZone)
 }
+
+func ToEnglishName(stdname, dstname string) (string, error) {
+       return toEnglishName(stdname, dstname)
+}
index 9f987ab30253e1bb295f24e779efe748c427d08d..d04ebec614ef75cb602568635d749ef433842d84 100644 (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
        }
index 9db81b7cfd7805946ac103ad3e7bba43d5c3c289..5f1141d3cae6daf95f0d46d7792e1da7510dbe4a 100644 (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)
+       }
+}