1 // Copyright 2013 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package time_test 6 7 import ( 8 "internal/syscall/windows/registry" 9 "testing" 10 . "time" 11 ) 12 13 func testZoneAbbr(t *testing.T) { 14 t1 := Now() 15 // discard nsec 16 t1 = Date(t1.Year(), t1.Month(), t1.Day(), t1.Hour(), t1.Minute(), t1.Second(), 0, t1.Location()) 17 t2, err := Parse(RFC1123, t1.Format(RFC1123)) 18 if err != nil { 19 t.Fatalf("Parse failed: %v", err) 20 } 21 if t1 != t2 { 22 t.Fatalf("t1 (%v) is not equal to t2 (%v)", t1, t2) 23 } 24 } 25 26 func TestLocalZoneAbbr(t *testing.T) { 27 ResetLocalOnceForTest() // reset the Once to trigger the race 28 defer ForceUSPacificForTesting() 29 testZoneAbbr(t) 30 } 31 32 func TestAusZoneAbbr(t *testing.T) { 33 ForceAusForTesting() 34 defer ForceUSPacificForTesting() 35 testZoneAbbr(t) 36 } 37 38 func TestToEnglishName(t *testing.T) { 39 const want = "Central Europe Standard Time" 40 k, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones\`+want, registry.READ) 41 if err != nil { 42 t.Fatalf("cannot open CEST time zone information from registry: %s", err) 43 } 44 defer k.Close() 45 46 var std, dlt string 47 if err = registry.LoadRegLoadMUIString(); err == nil { 48 // Try MUI_Std and MUI_Dlt first, fallback to Std and Dlt if *any* error occurs 49 std, err = k.GetMUIStringValue("MUI_Std") 50 if err == nil { 51 dlt, err = k.GetMUIStringValue("MUI_Dlt") 52 } 53 } 54 if err != nil { // Fallback to Std and Dlt 55 if std, _, err = k.GetStringValue("Std"); err != nil { 56 t.Fatalf("cannot read CEST Std registry key: %s", err) 57 } 58 if dlt, _, err = k.GetStringValue("Dlt"); err != nil { 59 t.Fatalf("cannot read CEST Dlt registry key: %s", err) 60 } 61 } 62 63 name, err := ToEnglishName(std, dlt) 64 if err != nil { 65 t.Fatalf("toEnglishName failed: %s", err) 66 } 67 if name != want { 68 t.Fatalf("english name: %q, want: %q", name, want) 69 } 70 } 71