blob: f23d9dcecb83ad2d6dd1209f9f9ef3912753c7a4 [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())
Alberto Donizetti193eda72017-08-01 17:41:51 +020017
Alex Brainman07ea2432013-06-06 16:30:25 +100018 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
Florian Uekermann7340d132017-09-18 19:22:29 +020027func TestUSPacificZoneAbbr(t *testing.T) {
28 ForceUSPacificFromTZIForTesting() // reset the Once to trigger the race
Alex Brainman07ea2432013-06-06 16:30:25 +100029 defer ForceUSPacificForTesting()
30 testZoneAbbr(t)
31}
32
33func TestAusZoneAbbr(t *testing.T) {
Florian Uekermann7340d132017-09-18 19:22:29 +020034 ForceAusFromTZIForTesting()
Alex Brainman07ea2432013-06-06 16:30:25 +100035 defer ForceUSPacificForTesting()
36 testZoneAbbr(t)
37}
Patrick Mezard51021cc2015-05-12 08:19:00 +020038
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()
Daniel Johanssoncba15282015-08-23 22:08:27 +020046
47 var std, dlt string
48 if err = registry.LoadRegLoadMUIString(); err == nil {
49 // Try MUI_Std and MUI_Dlt first, fallback to Std and Dlt if *any* error occurs
50 std, err = k.GetMUIStringValue("MUI_Std")
51 if err == nil {
52 dlt, err = k.GetMUIStringValue("MUI_Dlt")
53 }
Patrick Mezard51021cc2015-05-12 08:19:00 +020054 }
Daniel Johanssoncba15282015-08-23 22:08:27 +020055 if err != nil { // Fallback to Std and Dlt
56 if std, _, err = k.GetStringValue("Std"); err != nil {
57 t.Fatalf("cannot read CEST Std registry key: %s", err)
58 }
59 if dlt, _, err = k.GetStringValue("Dlt"); err != nil {
60 t.Fatalf("cannot read CEST Dlt registry key: %s", err)
61 }
Patrick Mezard51021cc2015-05-12 08:19:00 +020062 }
Daniel Johanssoncba15282015-08-23 22:08:27 +020063
Patrick Mezard51021cc2015-05-12 08:19:00 +020064 name, err := ToEnglishName(std, dlt)
65 if err != nil {
66 t.Fatalf("toEnglishName failed: %s", err)
67 }
68 if name != want {
69 t.Fatalf("english name: %q, want: %q", name, want)
70 }
71}