aboutsummaryrefslogtreecommitdiff
path: root/src/time/time_test.go
diff options
context:
space:
mode:
authorJoel Courtney <euphemize@gmail.com>2021-03-15 22:28:31 +0000
committerEmmanuel Odeke <emmanuel@orijtech.com>2021-03-15 23:56:07 +0000
commita9b3c4bd0602f95afc58328d9953534f5e5fe4f6 (patch)
tree78f4086aa4f063ff967a2032928ea4ff4ae529b5 /src/time/time_test.go
parentd7cc2f1d7c60b51c600c7d0c808610985dcd9b0c (diff)
downloadgo-a9b3c4bd0602f95afc58328d9953534f5e5fe4f6.tar.gz
go-a9b3c4bd0602f95afc58328d9953534f5e5fe4f6.zip
time: add Time.IsDST() to check if its Location is in Daylight Savings Time
Fixes #42102 Change-Id: I2cd2fdf67c794c3e99ed1c24786f7f779da73962 GitHub-Last-Rev: bbfa92135734cbd55895012fa492e51686a7b58b GitHub-Pull-Request: golang/go#42103 Reviewed-on: https://go-review.googlesource.com/c/go/+/264077 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com> Reviewed-by: Rob Pike <r@golang.org> Trust: Emmanuel Odeke <emmanuel@orijtech.com>
Diffstat (limited to 'src/time/time_test.go')
-rw-r--r--src/time/time_test.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/time/time_test.go b/src/time/time_test.go
index 154198a1ce..8884731e1d 100644
--- a/src/time/time_test.go
+++ b/src/time/time_test.go
@@ -1465,3 +1465,39 @@ func TestConcurrentTimerResetStop(t *testing.T) {
}
wg.Wait()
}
+
+func TestTimeIsDST(t *testing.T) {
+ ForceZipFileForTesting(true)
+ defer ForceZipFileForTesting(false)
+
+ tzWithDST, err := LoadLocation("Australia/Sydney")
+ if err != nil {
+ t.Fatalf("could not load tz 'Australia/Sydney': %v", err)
+ }
+ tzWithoutDST, err := LoadLocation("Australia/Brisbane")
+ if err != nil {
+ t.Fatalf("could not load tz 'Australia/Brisbane': %v", err)
+ }
+ tzFixed := FixedZone("FIXED_TIME", 12345)
+
+ tests := [...]struct {
+ time Time
+ want bool
+ }{
+ 0: {Date(2009, 1, 1, 12, 0, 0, 0, UTC), false},
+ 1: {Date(2009, 6, 1, 12, 0, 0, 0, UTC), false},
+ 2: {Date(2009, 1, 1, 12, 0, 0, 0, tzWithDST), true},
+ 3: {Date(2009, 6, 1, 12, 0, 0, 0, tzWithDST), false},
+ 4: {Date(2009, 1, 1, 12, 0, 0, 0, tzWithoutDST), false},
+ 5: {Date(2009, 6, 1, 12, 0, 0, 0, tzWithoutDST), false},
+ 6: {Date(2009, 1, 1, 12, 0, 0, 0, tzFixed), false},
+ 7: {Date(2009, 6, 1, 12, 0, 0, 0, tzFixed), false},
+ }
+
+ for i, tt := range tests {
+ got := tt.time.IsDST()
+ if got != tt.want {
+ t.Errorf("#%d:: (%#v).IsDST()=%t, want %t", i, tt.time.Format(RFC3339), got, tt.want)
+ }
+ }
+}