diff options
author | 2023-08-10 19:46:45 -0700 | |
---|---|---|
committer | 2023-08-10 20:29:34 -0700 | |
commit | 168a870c025bfef6efdeb46e166e79a16093c157 (patch) | |
tree | 4d8ab69c7e3ef03a7ade06e7b5e5053429a64c3b /internal/timezone/timezone_test.go | |
parent | c2349032552891745cbbc3d2a9e772845a0239f4 (diff) | |
download | v2-168a870c025bfef6efdeb46e166e79a16093c157.tar.gz v2-168a870c025bfef6efdeb46e166e79a16093c157.tar.zst v2-168a870c025bfef6efdeb46e166e79a16093c157.zip |
Move internal packages to an internal folder
For reference: https://go.dev/doc/go1.4#internalpackages
Diffstat (limited to 'internal/timezone/timezone_test.go')
-rw-r--r-- | internal/timezone/timezone_test.go | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/internal/timezone/timezone_test.go b/internal/timezone/timezone_test.go new file mode 100644 index 00000000..dc80c22f --- /dev/null +++ b/internal/timezone/timezone_test.go @@ -0,0 +1,74 @@ +// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +package timezone // import "miniflux.app/v2/internal/timezone" + +import ( + "testing" + "time" +) + +func TestNow(t *testing.T) { + tz := "Europe/Paris" + now := Now(tz) + + if now.Location().String() != tz { + t.Fatalf(`Unexpected timezone, got %q instead of %q`, now.Location(), tz) + } +} + +func TestNowWithInvalidTimezone(t *testing.T) { + tz := "Invalid Timezone" + expected := time.Local + now := Now(tz) + + if now.Location().String() != expected.String() { + t.Fatalf(`Unexpected timezone, got %q instead of %q`, now.Location(), expected) + } +} + +func TestConvertTimeWithNoTimezoneInformation(t *testing.T) { + tz := "Canada/Pacific" + input := time.Date(2018, 3, 1, 14, 2, 3, 0, time.FixedZone("", 0)) + output := Convert(tz, input) + + if output.Location().String() != tz { + t.Fatalf(`Unexpected timezone, got %q instead of %s`, output.Location(), tz) + } + + hours, minutes, secs := output.Clock() + if hours != 14 || minutes != 2 || secs != 3 { + t.Fatalf(`Unexpected time, got hours=%d, minutes=%d, secs=%d`, hours, minutes, secs) + } +} + +func TestConvertTimeWithDifferentTimezone(t *testing.T) { + tz := "Canada/Central" + input := time.Date(2018, 3, 1, 14, 2, 3, 0, time.UTC) + output := Convert(tz, input) + + if output.Location().String() != tz { + t.Fatalf(`Unexpected timezone, got %q instead of %s`, output.Location(), tz) + } + + hours, minutes, secs := output.Clock() + if hours != 8 || minutes != 2 || secs != 3 { + t.Fatalf(`Unexpected time, got hours=%d, minutes=%d, secs=%d`, hours, minutes, secs) + } +} + +func TestConvertTimeWithIdenticalTimezone(t *testing.T) { + tz := "Canada/Central" + loc, _ := time.LoadLocation(tz) + input := time.Date(2018, 3, 1, 14, 2, 3, 0, loc) + output := Convert(tz, input) + + if output.Location().String() != tz { + t.Fatalf(`Unexpected timezone, got %q instead of %s`, output.Location(), tz) + } + + hours, minutes, secs := output.Clock() + if hours != 14 || minutes != 2 || secs != 3 { + t.Fatalf(`Unexpected time, got hours=%d, minutes=%d, secs=%d`, hours, minutes, secs) + } +} |