3136352472 5 years ago
parent
commit
86624c9233
  1. 8
      core.go
  2. 10
      core_test.go

8
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

10
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)
}

Loading…
Cancel
Save