Skip to content

Commit 689143a

Browse files
committed
fix: time zone issue
1 parent 2a11e53 commit 689143a

File tree

2 files changed

+38
-36
lines changed

2 files changed

+38
-36
lines changed

main.go

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -186,38 +186,39 @@ END:DAYLIGHT
186186
END:VTIMEZONE
187187
`
188188

189+
var cstZone = time.FixedZone("CST", 8*3600)
189190
var basinTime time.Time
190191
var startTimes = []time.Time{
191-
time.Date(0, 0, 0, 0, 0, 0, 0, time.Local),
192-
time.Date(0, 0, 0, 8, 0, 0, 0, time.Local),
193-
time.Date(0, 0, 0, 8, 50, 0, 0, time.Local),
194-
time.Date(0, 0, 0, 9, 50, 0, 0, time.Local),
195-
time.Date(0, 0, 0, 10, 40, 0, 0, time.Local),
196-
time.Date(0, 0, 0, 11, 30, 0, 0, time.Local),
197-
time.Date(0, 0, 0, 14, 05, 0, 0, time.Local),
198-
time.Date(0, 0, 0, 14, 55, 0, 0, time.Local),
199-
time.Date(0, 0, 0, 15, 45, 0, 0, time.Local),
200-
time.Date(0, 0, 0, 16, 40, 0, 0, time.Local),
201-
time.Date(0, 0, 0, 17, 30, 0, 0, time.Local),
202-
time.Date(0, 0, 0, 18, 30, 0, 0, time.Local),
203-
time.Date(0, 0, 0, 19, 20, 0, 0, time.Local),
204-
time.Date(0, 0, 0, 20, 10, 0, 0, time.Local),
192+
time.Date(0, 0, 0, 0, 0, 0, 0, cstZone),
193+
time.Date(0, 0, 0, 8, 0, 0, 0, cstZone),
194+
time.Date(0, 0, 0, 8, 50, 0, 0, cstZone),
195+
time.Date(0, 0, 0, 9, 50, 0, 0, cstZone),
196+
time.Date(0, 0, 0, 10, 40, 0, 0, cstZone),
197+
time.Date(0, 0, 0, 11, 30, 0, 0, cstZone),
198+
time.Date(0, 0, 0, 14, 05, 0, 0, cstZone),
199+
time.Date(0, 0, 0, 14, 55, 0, 0, cstZone),
200+
time.Date(0, 0, 0, 15, 45, 0, 0, cstZone),
201+
time.Date(0, 0, 0, 16, 40, 0, 0, cstZone),
202+
time.Date(0, 0, 0, 17, 30, 0, 0, cstZone),
203+
time.Date(0, 0, 0, 18, 30, 0, 0, cstZone),
204+
time.Date(0, 0, 0, 19, 20, 0, 0, cstZone),
205+
time.Date(0, 0, 0, 20, 10, 0, 0, cstZone),
205206
}
206207
var endTimes = []time.Time{
207-
time.Date(0, 0, 0, 0, 0, 0, 0, time.Local),
208-
time.Date(0, 0, 0, 8, 45, 0, 0, time.Local),
209-
time.Date(0, 0, 0, 9, 35, 0, 0, time.Local),
210-
time.Date(0, 0, 0, 10, 35, 0, 0, time.Local),
211-
time.Date(0, 0, 0, 11, 25, 0, 0, time.Local),
212-
time.Date(0, 0, 0, 12, 15, 0, 0, time.Local),
213-
time.Date(0, 0, 0, 14, 50, 0, 0, time.Local),
214-
time.Date(0, 0, 0, 15, 40, 0, 0, time.Local),
215-
time.Date(0, 0, 0, 16, 30, 0, 0, time.Local),
216-
time.Date(0, 0, 0, 17, 25, 0, 0, time.Local),
217-
time.Date(0, 0, 0, 18, 15, 0, 0, time.Local),
218-
time.Date(0, 0, 0, 19, 15, 0, 0, time.Local),
219-
time.Date(0, 0, 0, 20, 05, 0, 0, time.Local),
220-
time.Date(0, 0, 0, 20, 55, 0, 0, time.Local),
208+
time.Date(0, 0, 0, 0, 0, 0, 0, cstZone),
209+
time.Date(0, 0, 0, 8, 45, 0, 0, cstZone),
210+
time.Date(0, 0, 0, 9, 35, 0, 0, cstZone),
211+
time.Date(0, 0, 0, 10, 35, 0, 0, cstZone),
212+
time.Date(0, 0, 0, 11, 25, 0, 0, cstZone),
213+
time.Date(0, 0, 0, 12, 15, 0, 0, cstZone),
214+
time.Date(0, 0, 0, 14, 50, 0, 0, cstZone),
215+
time.Date(0, 0, 0, 15, 40, 0, 0, cstZone),
216+
time.Date(0, 0, 0, 16, 30, 0, 0, cstZone),
217+
time.Date(0, 0, 0, 17, 25, 0, 0, cstZone),
218+
time.Date(0, 0, 0, 18, 15, 0, 0, cstZone),
219+
time.Date(0, 0, 0, 19, 15, 0, 0, cstZone),
220+
time.Date(0, 0, 0, 20, 05, 0, 0, cstZone),
221+
time.Date(0, 0, 0, 20, 55, 0, 0, cstZone),
221222
}
222223

223224
func GetClassTime(week, day, classStart, classEnd int) (start, end time.Time) {
@@ -236,7 +237,7 @@ func CreateCalendar(classInfos []ClassDetail) {
236237
timeInput, _ := reader.ReadString('\n')
237238
var year, month, day int
238239
fmt.Sscanf(timeInput, "%d-%d-%d", &year, &month, &day)
239-
basinTime = time.Date(year, time.Month(month), day, 0, 0, 0, 0, time.Local)
240+
basinTime = time.Date(year, time.Month(month), day, 0, 0, 0, 0, cstZone)
240241

241242
cal := ics.NewCalendar()
242243
for _, classInfo := range classInfos {

web.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"time"
1313

1414
"WHUClass/frontend"
15+
1516
ics "github.com/arran4/golang-ical"
1617
"github.com/google/uuid"
1718
)
@@ -24,10 +25,10 @@ type WebRequest struct {
2425

2526
// WebResponse represents the response to the frontend
2627
type WebResponse struct {
27-
Success bool `json:"success"`
28-
Message string `json:"message"`
29-
Calendar string `json:"calendar,omitempty"`
30-
Error string `json:"error,omitempty"`
28+
Success bool `json:"success"`
29+
Message string `json:"message"`
30+
Calendar string `json:"calendar,omitempty"`
31+
Error string `json:"error,omitempty"`
3132
ClassData []ClassDetail `json:"classData,omitempty"`
3233
}
3334

@@ -38,7 +39,7 @@ func indexHandler(w http.ResponseWriter, r *http.Request) {
3839
http.Error(w, "Template error: "+err.Error(), http.StatusInternalServerError)
3940
return
4041
}
41-
42+
4243
w.Header().Set("Content-Type", "text/html; charset=utf-8")
4344
if err := tmpl.Execute(w, nil); err != nil {
4445
http.Error(w, "Template execution error: "+err.Error(), http.StatusInternalServerError)
@@ -84,7 +85,7 @@ func generateHandler(w http.ResponseWriter, r *http.Request) {
8485
}
8586

8687
// Set global basin time
87-
basinTime = time.Date(year, time.Month(month), day, 0, 0, 0, 0, time.Local)
88+
basinTime = time.Date(year, time.Month(month), day, 0, 0, 0, 0, cstZone)
8889

8990
// Get class data
9091
kbListResp, err := getKBListSafe(req.CurlCommand)
@@ -236,4 +237,4 @@ func StartWebServer(port int) {
236237
fmt.Printf("⏹️ 按Ctrl+C停止服务\n\n")
237238

238239
log.Fatal(http.ListenAndServe(portStr, nil))
239-
}
240+
}

0 commit comments

Comments
 (0)