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 5package time_test 6 7import ( 8 "internal/syscall/windows/registry" 9 "testing" 10 . "time" 11) 12 13func 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 18 t2, err := Parse(RFC1123, t1.Format(RFC1123)) 19 if err != nil { 20 t.Fatalf("Parse failed: %v", err) 21 } 22 if t1 != t2 { 23 t.Fatalf("t1 (%v) is not equal to t2 (%v)", t1, t2) 24 } 25} 26 27func TestUSPacificZoneAbbr(t *testing.T) { 28 ForceUSPacificFromTZIForTesting() // reset the Once to trigger the race 29 defer ForceUSPacificForTesting() 30 testZoneAbbr(t) 31} 32 33func TestAusZoneAbbr(t *testing.T) { 34 ForceAusFromTZIForTesting() 35 defer ForceUSPacificForTesting() 36 testZoneAbbr(t) 37} 38 39func TestToEnglishName(t *testing.T) { 40 const want = "Central Europe Standard Time" 41 k, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones\`+want, registry.READ) 42 if err != nil { 43 t.Fatalf("cannot open CEST time zone information from registry: %s", err) 44 } 45 defer k.Close() 46 47 var std, dlt string 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 if err != nil { // Fallback to Std and Dlt 54 if std, _, err = k.GetStringValue("Std"); err != nil { 55 t.Fatalf("cannot read CEST Std registry key: %s", err) 56 } 57 if dlt, _, err = k.GetStringValue("Dlt"); err != nil { 58 t.Fatalf("cannot read CEST Dlt registry key: %s", err) 59 } 60 } 61 62 name, err := ToEnglishName(std, dlt) 63 if err != nil { 64 t.Fatalf("toEnglishName failed: %s", err) 65 } 66 if name != want { 67 t.Fatalf("english name: %q, want: %q", name, want) 68 } 69} 70