Home | History | Annotate | Download | only in time
      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 	std, _, err := k.GetStringValue("Std")
     46 	if err != nil {
     47 		t.Fatalf("cannot read CEST Std registry key: %s", err)
     48 	}
     49 	dlt, _, err := k.GetStringValue("Dlt")
     50 	if err != nil {
     51 		t.Fatalf("cannot read CEST Dlt registry key: %s", err)
     52 	}
     53 	name, err := ToEnglishName(std, dlt)
     54 	if err != nil {
     55 		t.Fatalf("toEnglishName failed: %s", err)
     56 	}
     57 	if name != want {
     58 		t.Fatalf("english name: %q, want: %q", name, want)
     59 	}
     60 }
     61