mirror of
https://github.com/Xevion/go-ha.git
synced 2025-12-09 14:07:24 -06:00
split daily schedule and interval
This commit is contained in:
22
listeners.go
22
listeners.go
@@ -4,6 +4,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/golang-module/carbon"
|
||||
"github.com/saml-dev/gome-assistant/internal"
|
||||
i "github.com/saml-dev/gome-assistant/internal"
|
||||
)
|
||||
|
||||
@@ -85,3 +86,24 @@ func checkExceptionRanges(eList []timeRange) conditionCheck {
|
||||
}
|
||||
return cc
|
||||
}
|
||||
|
||||
func checkStartEndTime(s TimeString, isStart bool) conditionCheck {
|
||||
cc := conditionCheck{fail: false}
|
||||
// pass immediately if default
|
||||
if s == "00:00" {
|
||||
return cc
|
||||
}
|
||||
|
||||
now := time.Now()
|
||||
parsedTime := internal.ParseTime(string(s)).Carbon2Time()
|
||||
if isStart {
|
||||
if parsedTime.After(now) {
|
||||
cc.fail = true
|
||||
}
|
||||
} else {
|
||||
if parsedTime.Before(now) {
|
||||
cc.fail = true
|
||||
}
|
||||
}
|
||||
return cc
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user