github.com/golang-haiku/go-1.4.3@v0.0.0-20190609233734-1f5ae41cc308/src/time/zoneinfo_test.go (about)

     1  // Copyright 2014 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  	"testing"
     9  	"time"
    10  )
    11  
    12  func TestVersion3(t *testing.T) {
    13  	time.ForceZipFileForTesting(true)
    14  	defer time.ForceZipFileForTesting(false)
    15  	_, err := time.LoadLocation("Asia/Jerusalem")
    16  	if err != nil {
    17  		t.Fatal(err)
    18  	}
    19  }
    20  
    21  // Test that we get the correct results for times before the first
    22  // transition time.  To do this we explicitly check early dates in a
    23  // couple of specific timezones.
    24  func TestFirstZone(t *testing.T) {
    25  	time.ForceZipFileForTesting(true)
    26  	defer time.ForceZipFileForTesting(false)
    27  
    28  	const format = "Mon, 02 Jan 2006 15:04:05 -0700 (MST)"
    29  	var tests = []struct {
    30  		zone  string
    31  		unix  int64
    32  		want1 string
    33  		want2 string
    34  	}{
    35  		{
    36  			"PST8PDT",
    37  			-1633269601,
    38  			"Sun, 31 Mar 1918 01:59:59 -0800 (PST)",
    39  			"Sun, 31 Mar 1918 03:00:00 -0700 (PDT)",
    40  		},
    41  		{
    42  			"Pacific/Fakaofo",
    43  			1325242799,
    44  			"Thu, 29 Dec 2011 23:59:59 -1100 (TKT)",
    45  			"Sat, 31 Dec 2011 00:00:00 +1300 (TKT)",
    46  		},
    47  	}
    48  
    49  	for _, test := range tests {
    50  		z, err := time.LoadLocation(test.zone)
    51  		if err != nil {
    52  			t.Fatal(err)
    53  		}
    54  		s := time.Unix(test.unix, 0).In(z).Format(format)
    55  		if s != test.want1 {
    56  			t.Errorf("for %s %d got %q want %q", test.zone, test.unix, s, test.want1)
    57  		}
    58  		s = time.Unix(test.unix+1, 0).In(z).Format(format)
    59  		if s != test.want2 {
    60  			t.Errorf("for %s %d got %q want %q", test.zone, test.unix, s, test.want2)
    61  		}
    62  	}
    63  }