-
Notifications
You must be signed in to change notification settings - Fork 3
/
get-classes-today.go
56 lines (41 loc) · 1.23 KB
/
get-classes-today.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
package main
import (
"sort"
"strconv"
"strings"
"time"
)
func get_time_from_hh_mm(hh_mm_str string) time.Time {
timeArr := strings.Split(hh_mm_str, ":")
hours, _ := strconv.Atoi(timeArr[0])
minutes, _ := strconv.Atoi(timeArr[1])
currentTime := time.Now()
time := time.Date(currentTime.Year(), currentTime.Month(), currentTime.Day(), hours, minutes, 0, currentTime.Nanosecond(), currentTime.Location())
return time
}
func getClassesToday(config ClassConfig, weekDay string) []ClassToday {
classesToday := []ClassToday{}
for className, classContent := range config {
todayTime := ClassTime{}
for _, val := range classContent.Times {
if val.Day == weekDay {
todayTime = val
}
}
// No time found, then move on
if (todayTime == ClassTime{}) {
continue
}
time := get_time_from_hh_mm(todayTime.Time)
classesToday = append(classesToday, ClassToday{link: classContent.Link, name: className, time: time})
}
if len(todaysClassLaunched) == 0 {
for _, classContent := range classesToday {
todaysClassLaunched[classContent.name] = time.Now().After(classContent.time)
}
}
sort.Slice(classesToday, func(i, j int) bool {
return classesToday[i].time.Before(classesToday[j].time)
})
return classesToday
}