Source file src/time/zoneinfo_windows_test.go

Documentation: 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  
    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() // reset the Once to trigger the race
    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  	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  		}
    54  	}
    55  	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  		}
    62  	}
    63  
    64  	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  }
    72  

View as plain text