...
Source file
src/time/zoneinfo_windows_test.go
Documentation: time
1
2
3
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
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
27 func TestUSPacificZoneAbbr(t *testing.T) {
28 ForceUSPacificFromTZIForTesting()
29 defer ForceUSPacificForTesting()
30 testZoneAbbr(t)
31 }
32
33 func TestAusZoneAbbr(t *testing.T) {
34 ForceAusFromTZIForTesting()
35 defer ForceUSPacificForTesting()
36 testZoneAbbr(t)
37 }
38
39 func 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
49 std, err = k.GetMUIStringValue("MUI_Std")
50 if err == nil {
51 dlt, err = k.GetMUIStringValue("MUI_Dlt")
52 }
53 if err != nil {
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
View as plain text