-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
example_test.go
138 lines (114 loc) · 2.99 KB
/
example_test.go
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
package timezone_test
import (
"fmt"
"time"
"github.com/tkuchiki/go-timezone"
)
func ExampleTimezone_GetTzAbbreviationInfo() {
tz := timezone.New()
tzAbbrInfos, _ := tz.GetTzAbbreviationInfo("EET")
fmt.Println(tzAbbrInfos[0].Name())
fmt.Println(tzAbbrInfos[0].Offset())
fmt.Println(tzAbbrInfos[0].OffsetHHMM())
// Output:
// Eastern European Time/Eastern European Standard Time
// 7200
// +02:00
}
func ExampleTimezone_GetTzAbbreviationInfo_ambiguousTimezoneAbbreviationsError() {
tz := timezone.New()
tzAbbrInfos, _ := tz.GetTzAbbreviationInfo("BST")
fmt.Println(tzAbbrInfos[0].Name())
fmt.Println(tzAbbrInfos[0].Offset())
fmt.Println(tzAbbrInfos[0].OffsetHHMM())
fmt.Println(tzAbbrInfos[1].Name())
fmt.Println(tzAbbrInfos[1].Offset())
fmt.Println(tzAbbrInfos[1].OffsetHHMM())
fmt.Println(tzAbbrInfos[2].Name())
fmt.Println(tzAbbrInfos[2].Offset())
fmt.Println(tzAbbrInfos[2].OffsetHHMM())
// Output:
// Bolivia Summer Time
// -12756
// -03:27
// British Summer Time
// 3600
// +01:00
// Bougainville Standard Time
// 39600
// +11:00
}
func ExampleTimezone_GetTzAbbreviationInfoByTZName() {
tz := timezone.New()
tzAbbrInfo, _ := tz.GetTzAbbreviationInfoByTZName("BST", "British Summer Time")
fmt.Println(tzAbbrInfo.Name())
fmt.Println(tzAbbrInfo.Offset())
fmt.Println(tzAbbrInfo.OffsetHHMM())
// Output:
// British Summer Time
// 3600
// +01:00
}
func ExampleTimezone_GetTimezones() {
tz := timezone.New()
timezones, _ := tz.GetTimezones("UTC")
fmt.Println(timezones)
// Output:
// [Etc/UCT Etc/UTC Etc/Universal Etc/Zulu UCT UTC Universal Zulu]
}
func ExampleTimezone_FixedTimezone() {
tz := timezone.New()
_time := time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC)
fixedTime, _ := tz.FixedTimezone(_time, "Europe/Belgrade")
fmt.Println(fixedTime)
// Output:
// 2020-01-01 01:00:00 +0100 CET
}
func ExampleTimezone_GetTzInfo() {
tz := timezone.New()
tzInfo, _ := tz.GetTzInfo("Europe/London")
fmt.Println(tzInfo.LongStandard())
fmt.Println(tzInfo.ShortStandard())
fmt.Println(tzInfo.StandardOffset())
fmt.Println(tzInfo.StandardOffsetHHMM())
fmt.Println(tzInfo.LongDaylight())
fmt.Println(tzInfo.ShortDaylight())
fmt.Println(tzInfo.DaylightOffset())
fmt.Println(tzInfo.DaylightOffsetHHMM())
// Output:
// Greenwich Mean Time
// GMT
// 0
// +00:00
// British Summer Time
// BST
// 3600
// +01:00
}
func ExampleTimezone_GetTimezoneAbbreviation() {
tz := timezone.New()
abbr, _ := tz.GetTimezoneAbbreviation("Europe/London")
fmt.Println(abbr)
// Output:
// GMT
}
func ExampleTimezone_GetTimezoneAbbreviation_dst() {
tz := timezone.New()
abbr, _ := tz.GetTimezoneAbbreviation("Europe/London", true)
fmt.Println(abbr)
// Output:
// BST
}
func ExampleTimezone_IsDST() {
tz := timezone.New()
loc, _ := time.LoadLocation("America/New_York")
_time := time.Date(2021, 7, 1, 0, 0, 0, 0, loc)
isDST := tz.IsDST(_time)
_time = time.Date(2021, 1, 1, 0, 0, 0, 0, loc)
isNotDST := tz.IsDST(_time)
fmt.Println(isDST)
fmt.Println(isNotDST)
// Output:
// true
// false
}