/
time.go
60 lines (52 loc) · 1.27 KB
/
time.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
package main
import (
"time"
)
func isTimeBetween(t1, t2 time.Time) bool {
now, _ := time.Parse("15:04", time.Now().Format("15:04"))
if now.After(t1) && now.Before(t2) {
return true
} else if now.Equal(t1) {
return true
} else {
return false
}
}
func isDayTime() bool {
return isTimeBetween(config.Day.StartTime, config.Night.StartTime)
}
func isSunrise() bool {
return isTimeBetween(config.Sunrise.StartTime, config.Day.StartTime)
}
func isSunset() bool {
return isTimeBetween(config.Sunset.StartTime, config.Night.StartTime)
}
func InitTime() {
go monitorTime()
}
func monitorTime() {
for {
if isSunrise() {
Debug("Setting Sunrise configuration")
for _, a := range config.Sunrise.Action {
RunAction(a, "Setting sunrise configuration")
}
} else if isSunset() {
Debug("Setting Sunset configuration")
for _, a := range config.Sunset.Action {
RunAction(a, "Setting Sunset configuration")
}
} else if isDayTime() {
Debug("Setting Day Time configuration")
for _, a := range config.Day.Action {
RunAction(a, "Setting Day Time configuration")
}
} else {
Debug("Setting Night Time configuration")
for _, a := range config.Night.Action {
RunAction(a, "Setting Night Time configuration")
}
}
time.Sleep(1 * time.Minute)
}
}