-
Notifications
You must be signed in to change notification settings - Fork 1
/
calendar_test.go
58 lines (55 loc) · 1.63 KB
/
calendar_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
package server_test
import (
"testing"
"time"
server "github.com/brackendawson/webcal-proxy"
"github.com/stretchr/testify/require"
)
func TestDaySameDate(t *testing.T) {
for name, test := range map[string]struct {
a, b time.Time
expected bool
}{
"identical": {
a: time.Date(2024, 9, 24, 00, 00, 0, 0, time.UTC),
b: time.Date(2024, 9, 24, 00, 00, 0, 0, time.UTC),
expected: true,
},
"close_enough": {
a: time.Date(2024, 9, 24, 00, 00, 0, 0, time.UTC),
b: time.Date(2024, 9, 24, 23, 59, 59, 999_999_999, time.UTC),
expected: true,
},
"different_locations_same_date": {
a: time.Date(2024, 9, 24, 23, 00, 0, 0, time.UTC),
b: time.Date(2024, 9, 24, 23, 00, 0, 0, locSydney),
expected: true,
},
"different_day": {
a: time.Date(2024, 9, 24, 00, 00, 0, 0, time.UTC),
b: time.Date(2024, 9, 25, 00, 00, 0, 0, time.UTC),
expected: false,
},
"different_month": {
a: time.Date(2024, 9, 24, 00, 00, 0, 0, time.UTC),
b: time.Date(2024, 10, 24, 00, 00, 0, 0, time.UTC),
expected: false,
},
"different_year": {
a: time.Date(2024, 9, 24, 00, 00, 0, 0, time.UTC),
b: time.Date(2025, 9, 24, 00, 00, 0, 0, time.UTC),
expected: false,
},
"different_locations_different_date": {
// but would be the same date in UTC
a: time.Date(2024, 9, 24, 23, 00, 0, 0, time.UTC),
b: time.Date(2025, 9, 25, 01, 00, 0, 0, locSydney),
expected: false,
},
} {
t.Run(name, func(t *testing.T) {
t.Parallel()
require.Equal(t, test.expected, server.Day{Time: test.a}.SameDate(test.b))
})
}
}