Skip to content

Commit bb0490f

Browse files
committed
feat: update school const
1 parent 7f51a65 commit bb0490f

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

schoolConst/const.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,58 @@
11
package schoolConst
22

3+
import (
4+
"math"
5+
"time"
6+
)
7+
38
const (
49
SchoolYear = 2023
510
Semester = 2
611
SemesterStartTimestamp = int64(1709481600)
712
)
13+
14+
func getWeekNum() int {
15+
timeStart := SemesterStartTimestamp
16+
return int(math.Floor(float64(time.Now().Unix()-timeStart)/(86400*7))) + 1
17+
}
18+
19+
func getWeekDay() int {
20+
day := int(time.Now().Weekday())
21+
return day
22+
}
23+
24+
type TimeData struct {
25+
SchoolYear int `json:"schoolYear"`
26+
Semester int `json:"semester"`
27+
SemesterStartTimestamp int64 `json:"semester_start_timestamp"`
28+
WeekNow int `json:"weekNow"`
29+
WeekDayNow int `json:"weekDayNow"`
30+
Timestamp int64 `json:"timeStamp"`
31+
Section int `json:"section"`
32+
}
33+
34+
func GetTimeData() *TimeData {
35+
timeNow := time.Now()
36+
hour := timeNow.Hour()
37+
minute := time.Now().Minute() + hour*60
38+
tMap := []int{0, 530, 580, 645, 695, 745, 855, 905, 960, 1010, 1155, 1205, 1255}
39+
section := -1
40+
for i := 0; i < len(tMap); i++ {
41+
if minute < tMap[i] {
42+
section = i
43+
break
44+
}
45+
}
46+
47+
timed := &TimeData{
48+
SchoolYear: SchoolYear,
49+
Semester: Semester,
50+
SemesterStartTimestamp: SemesterStartTimestamp,
51+
WeekNow: getWeekNum(),
52+
WeekDayNow: getWeekDay(),
53+
Timestamp: time.Now().Unix(),
54+
Section: section,
55+
}
56+
57+
return timed
58+
}

0 commit comments

Comments
 (0)