mirror of
https://github.com/Xevion/go-ha.git
synced 2025-12-09 10:07:25 -06:00
add Exceptions to eventListener
This commit is contained in:
25
listeners.go
25
listeners.go
@@ -60,3 +60,28 @@ func checkThrottle(throttle time.Duration, lastRan carbon.Carbon) conditionCheck
|
||||
}
|
||||
return cc
|
||||
}
|
||||
|
||||
func checkExceptionDays(eList []time.Time) conditionCheck {
|
||||
cc := conditionCheck{fail: false}
|
||||
for _, e := range eList {
|
||||
y1, m1, d1 := e.Date()
|
||||
y2, m2, d2 := time.Now().Date()
|
||||
if y1 == y2 && m1 == m2 && d1 == d2 {
|
||||
cc.fail = true
|
||||
break
|
||||
}
|
||||
}
|
||||
return cc
|
||||
}
|
||||
|
||||
func checkExceptionRanges(eList []timeRange) conditionCheck {
|
||||
cc := conditionCheck{fail: false}
|
||||
now := time.Now()
|
||||
for _, eRange := range eList {
|
||||
if now.After(eRange.start) && now.Before(eRange.end) {
|
||||
cc.fail = true
|
||||
break
|
||||
}
|
||||
}
|
||||
return cc
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user