blob: 7ac1e8682238ead39744b9d0368e3acf58670986 [file] [log] [blame]
Alex Brainman07ea2432013-06-06 16:30:25 +10001// 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 (
Patrick Mezard51021cc2015-05-12 08:19:00 +02008 "internal/syscall/windows/registry"
Alex Brainman07ea2432013-06-06 16:30:25 +10009 "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 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
26func TestLocalZoneAbbr(t *testing.T) {
27 ResetLocalOnceForTest() // reset the Once to trigger the race
28 defer ForceUSPacificForTesting()
29 testZoneAbbr(t)
30}
31
32func TestAusZoneAbbr(t *testing.T) {
33 ForceAusForTesting()
34 defer ForceUSPacificForTesting()
35 testZoneAbbr(t)
36}
Patrick Mezard51021cc2015-05-12 08:19:00 +020037
38func 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()
Daniel Johanssoncba15282015-08-23 22:08:27 +020045
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 }
Patrick Mezard51021cc2015-05-12 08:19:00 +020053 }
Daniel Johanssoncba15282015-08-23 22:08:27 +020054 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 }
Patrick Mezard51021cc2015-05-12 08:19:00 +020061 }
Daniel Johanssoncba15282015-08-23 22:08:27 +020062
Patrick Mezard51021cc2015-05-12 08:19:00 +020063 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}