-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimzone_test.go
48 lines (40 loc) · 1.29 KB
/
timzone_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
package tbb_test
import (
"github.com/apperia-de/tbb"
"github.com/evanoberholster/timezoneLookup/v2"
"github.com/stretchr/testify/assert"
"testing"
)
func TestApp_GetTimezoneInfo(t *testing.T) {
t.Run("Get TimezoneInfo for valid coordinates", func(t *testing.T) {
cfg := tbb.LoadConfig("test/data/test.config.yml")
app := tbb.New(tbb.WithConfig(cfg))
tzi, err := app.GetTimezoneInfo(51.340847907357755, 12.377381803667586)
assert.NoError(t, err)
assert.NotNil(t, tzi)
assert.Equal(t, 51.340847907357755, tzi.Latitude)
assert.Equal(t, 12.377381803667586, tzi.Longitude)
})
t.Run("Get TimezoneInfo for invalid coordinates", func(t *testing.T) {
cfg := tbb.LoadConfig("test/data/test.config.yml")
app := tbb.New(tbb.WithConfig(cfg))
tzi, err := app.GetTimezoneInfo(-125.123, 0)
assert.Nil(t, tzi)
assert.ErrorIs(t, err, timezoneLookup.ErrCoordinatesNotValid)
})
}
func TestApp_GetCurrentTimeOffset(t *testing.T) {
cfg := tbb.LoadConfig("test/data/test.config.yml")
app := tbb.New(tbb.WithConfig(cfg))
lat, lon := 51.340847907357755, 12.377381803667586
tzi, err := app.GetTimezoneInfo(lat, lon)
assert.NoError(t, err)
offset := app.GetCurrentTimeOffset(lat, lon)
if tzi.IsDST {
// Summer
assert.Equal(t, 7200, offset)
} else {
// Winter
assert.Equal(t, 3600, offset)
}
}