-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathTimerFunctions.go
72 lines (62 loc) · 1.77 KB
/
TimerFunctions.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
69
70
71
72
package main
import (
"os"
"path/filepath"
"strconv"
"time"
)
func writeTimerList(timers *[]TimerEntity, parentDir string, seenNames map[string]bool) {
for i := range *timers {
timer := &(*timers)[i]
if timer.IsFolder == "no" {
handleTimers(&timer.Timers, parentDir, seenNames)
}
writeScriptFiles(timer, parentDir, seenNames)
}
}
func writeTimerJson(timers *[]TimerEntity, parentDir string) {
for i := range *timers {
timer := &(*timers)[i]
ConvertTimeToSingleProperties(timer)
}
writeJsonToFilewriteJsonToFile(timers, parentDir, "timers.json")
}
func handleTimers(timers *[]TimerEntity, parentDir string, seenNames map[string]bool) {
if len(*timers) == 0 {
return
}
if parentDir != "" {
if err := os.MkdirAll(parentDir, 0755); err != nil {
panic(err)
}
}
writeTimerList(timers, parentDir, seenNames)
writeTimerJson(timers, parentDir)
}
func handleTimerGroups(groups *[]TimerEntity, baseDir string, seenNames map[string]bool) {
for i := range *groups {
group := &(*groups)[i]
groupPath := filepath.Join(baseDir, group.Name)
if err := os.MkdirAll(groupPath, 0755); err != nil {
panic(err)
}
handleTimers(&group.Timers, groupPath, seenNames)
handleTimerGroups(&group.TimerGroup, groupPath, seenNames)
group.Timers = nil
var singleGroup []TimerEntity
singleGroup = append(singleGroup, *group)
writeTimerList(&singleGroup, baseDir, seenNames)
writeTimerJson(&singleGroup, baseDir)
}
}
func ConvertTimeToSingleProperties(timer *TimerEntity) TimerEntity {
t, err := time.Parse("15:04:05.000", timer.Time)
if err != nil {
panic(err)
}
timer.Hours = strconv.Itoa(t.Hour())
timer.Minutes = strconv.Itoa(t.Minute())
timer.Seconds = strconv.Itoa(t.Second())
timer.Milliseconds = strconv.Itoa(t.Nanosecond() / 1000000)
return *timer
}