-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschedule_test.go
68 lines (58 loc) · 1.78 KB
/
schedule_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
package filterschedule
import (
"encoding/json"
"testing"
"time"
)
func TestDayOfTheWeekJSON(t *testing.T) {
v := `["Monday", "Sunday"]`
var d []DayOfTheWeek
err := json.Unmarshal([]byte(v), &d)
if err != nil {
t.Fatal("JSON deserialization should return no error:", err)
}
if len(d) != 2 {
t.Fatal("JSON deserialization should return 2 entries")
}
if d[0] != DayOfTheWeek(time.Monday) {
t.Fatal("JSON deserialization should return time.Monday value")
}
}
func TestTimeInterval(t *testing.T) {
interval := TimeInteval{From: "08:00", To: "20:00"}
timestamp := time.Date(2022, 5, 7, 0, 0, 0, 0, time.UTC)
if interval.includes(timestamp) {
t.Fatal(interval, " should not include ", timestamp)
}
timestamp = time.Date(2022, 5, 9, 8, 0, 0, 0, time.UTC)
if interval.includes(timestamp) {
t.Fatal(interval, " should not include ", timestamp)
}
timestamp = time.Date(2022, 5, 9, 8, 0, 1, 0, time.UTC)
if !interval.includes(timestamp) {
t.Fatal(interval, " should include ", timestamp)
}
timestamp = time.Date(2022, 5, 9, 19, 59, 59, 0, time.UTC)
if !interval.includes(timestamp) {
t.Fatal(interval, " should include ", timestamp)
}
timestamp = time.Date(2022, 5, 7, 20, 0, 0, 0, time.UTC)
if interval.includes(timestamp) {
t.Fatal(interval, " should not include ", timestamp)
}
location, err := time.LoadLocation("Europe/Brussels")
if err != nil {
panic(err)
}
timestamp = time.Date(2022, 5, 9, 21, 0, 0, 0, location)
if interval.includes(timestamp) {
t.Fatal(interval, " should not include ", timestamp)
}
}
func TestTimeIntervalWithZone(t *testing.T) {
interval := TimeInteval{From: "08:00+02", To: "20:00+02"}
timestamp := time.Date(2022, 5, 7, 12, 0, 0, 0, time.UTC)
if interval.includes(timestamp) {
t.Fatal(interval, " should not include ", timestamp)
}
}