File: timezone_test.go

package info (click to toggle)
miniflux 2.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 5,300 kB
  • sloc: xml: 4,809; javascript: 1,344; sh: 263; makefile: 179
file content (80 lines) | stat: -rw-r--r-- 2,260 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// 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"

	// Make sure these tests pass when the timezone database is not installed on the host system.
	_ "time/tzdata"
)

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) {
	t.SkipNow()
	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) {
	t.SkipNow()
	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) {
	t.SkipNow()
	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)
	}
}