From 86624c92333cac17311e7a7a7fbfe27ff704ac12 Mon Sep 17 00:00:00 2001 From: 3136352472 <3136352472> Date: Fri, 12 Jun 2020 13:26:11 +0800 Subject: [PATCH] fix --- core.go | 8 ++++---- core_test.go | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/core.go b/core.go index 1f8119c..5733b7d 100644 --- a/core.go +++ b/core.go @@ -64,13 +64,13 @@ func isInDateSlice(t time.Time, ta TimeArrow) bool { } endStr = strings.Join(endSc, " ") - startTime, err := time.Parse("2006-01-02 15:04:05", startStr) + startTime, err := time.ParseInLocation("2006-01-02 15:04:05", startStr, time.Local) if err != nil { log.Println("时间段开始时间格式错误", startStr) continue } - endTime, err := time.Parse("2006-01-02 15:04:05", endStr) + endTime, err := time.ParseInLocation("2006-01-02 15:04:05", endStr, time.Local) if err != nil { log.Println("时间段结束时间格式错误", startStr) continue @@ -130,12 +130,12 @@ func isInTimeOfDay(t time.Time, ta TimeArrow) bool { start, end := tsp[0], tsp[1] start = timeCompletion(start) end = timeCompletion(end) - startTime, err := time.Parse("2006-01-02 15:04:05", fmt.Sprintf("%s %s", t.Format("2006-01-02"), start)) + startTime, err := time.ParseInLocation("2006-01-02 15:04:05", fmt.Sprintf("%s %s", t.Format("2006-01-02"), start), time.Local) if err != nil { log.Println("时间段开始时间格式错误", start) continue } - endTime, err := time.Parse("2006-01-02 15:04:05", fmt.Sprintf("%s %s", t.Format("2006-01-02"), end)) + endTime, err := time.ParseInLocation("2006-01-02 15:04:05", fmt.Sprintf("%s %s", t.Format("2006-01-02"), end), time.Local) if err != nil { log.Println("时间段结束时间格式错误", end) continue diff --git a/core_test.go b/core_test.go index f27d82a..5a27cb2 100644 --- a/core_test.go +++ b/core_test.go @@ -6,7 +6,7 @@ import ( ) func Test_isInWeekOfDay(t *testing.T) { - ti, err := time.Parse("2006-01-02 15:04:05", "2020-06-08 00:00:00") + ti, err := time.ParseInLocation("2006-01-02 15:04:05", "2020-06-08 00:00:00", time.Local) if err != nil { panic(err) } @@ -45,7 +45,7 @@ func Test_timeCompletion(t *testing.T) { } func Test_isInTimeOfDay(t *testing.T) { - ti, err := time.Parse("2006-01-02 15:04:05", "2020-06-08 17:18:00") + ti, err := time.ParseInLocation("2006-01-02 15:04:05", "2020-06-08 17:18:00", time.Local) if err != nil { panic(err) } @@ -71,7 +71,7 @@ func Test_isInTimeOfDay(t *testing.T) { } func Test_isInDateSlice(t *testing.T) { - ti, err := time.Parse("2006-01-02 15:04:05", "2020-06-08 17:18:00") + ti, err := time.ParseInLocation("2006-01-02 15:04:05", "2020-06-08 17:18:00", time.Local) if err != nil { panic(err) } @@ -246,7 +246,7 @@ func TestGetHitTimeArrow(t *testing.T) { return tas, nil } - ti, err := time.Parse("2006-01-02 15:04:05", "2020-06-01 17:18:00") + ti, err := time.ParseInLocation("2006-01-02 15:04:05", "2020-06-01 17:18:00", time.Local) if err != nil { panic(err) } @@ -281,7 +281,7 @@ func TestGetHitTimeArrow(t *testing.T) { t.Fatal("error") } - ti, err = time.Parse("2006-01-02 15:04:05", "2020-04-11 17:18:00") + ti, err = time.ParseInLocation("2006-01-02 15:04:05", "2020-04-11 17:18:00", time.Local) if err != nil { panic(err) }