-
Notifications
You must be signed in to change notification settings - Fork 0
/
period.go
68 lines (58 loc) · 1.5 KB
/
period.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 calendar
import (
"time"
)
// Period of the calendars
type Period struct {
Included bool `json:"included"`
DateTimeIntervals *dateTimeInterval `json:"dateTimeIntervals,omitempty"`
MonthsOfYear *monthInterval `json:"monthsOfYear,omitempty"`
DaysOfMonth *dayInterval `json:"daysOfMonth,omitempty"`
DaysOfWeek *dayWeekInterval `json:"daysOfWeek,omitempty"`
HoursOfDay *hoursInterval `json:"hoursOfDay,omitempty"`
}
func (p Period) containsWithTz(t time.Time, tz *time.Location) (PeriodStatus, PeriodStatus, PeriodStatus) {
statusMonth := NoInfo
statusDay := NoInfo
statusTime := NoInfo
if p.DateTimeIntervals != nil {
if p.DateTimeIntervals.containsWithTz(t, tz) {
statusMonth = InPeriod
statusDay = InPeriod
statusTime = InPeriod
} else {
statusMonth = OutOfPeriod
statusDay = OutOfPeriod
statusTime = OutOfPeriod
}
}
if p.MonthsOfYear != nil {
if p.MonthsOfYear.containsWithTz(t, tz) {
statusMonth = InPeriod
} else {
statusMonth = OutOfPeriod
}
}
if p.DaysOfMonth != nil {
if p.DaysOfMonth.containsWithTz(t, tz) {
statusDay = InPeriod
} else {
statusDay = OutOfPeriod
}
}
if p.DaysOfWeek != nil {
if p.DaysOfWeek.containsWithTz(t, tz) {
statusDay = InPeriod
} else {
statusDay = OutOfPeriod
}
}
if p.HoursOfDay != nil {
if p.HoursOfDay.containsWithTz(t, tz) {
statusTime = InPeriod
} else {
statusTime = OutOfPeriod
}
}
return statusMonth, statusDay, statusTime
}