diff --git a/core.go b/core.go index b6a6261..d4b9f43 100644 --- a/core.go +++ b/core.go @@ -154,6 +154,10 @@ func isInTimeOfDay(t time.Time, ta TimeArrow) bool { continue } start, end := tsp[0], tsp[1] + if end == "24" || end == "24:00" || end == "24:00:00" { + end = "23:59:59" + } + start = timeCompletion(start) end = timeCompletion(end) fmt.Println("ssee", start, end, tfdate) @@ -171,15 +175,16 @@ func isInTimeOfDay2(t time.Time, ta TimeArrow) bool { return true } - t, _ = time.ParseInLocation("2006-01-02 15:04:05", "2011-01-01 "+t.Format("15:04:05"), time.Local) + // t, _ = time.ParseInLocation("2006-01-02 15:04:05", "2011-01-01 "+t.Format("15:04:05"), time.Local) tfdate := t.Format("2006-01-02") - cacheKey := fmt.Sprint(t.Format("15:04:05"), strings.Join(ta.TimesOnDay, "|")) - ret, ok := inTimeOfDayCache.Load(cacheKey) - if ok { - return ret.(bool) - } + // cacheKey := fmt.Sprint(t.Format("15:04:05"), strings.Join(ta.TimesOnDay, "|")) + + // ret, ok := inTimeOfDayCache.Load(cacheKey) + // if ok { + // return ret.(bool) + // } // var err error for k := range ta.TimesOnDay { @@ -222,11 +227,11 @@ func isInTimeOfDay2(t time.Time, ta TimeArrow) bool { } if (t.After(startTime) || t.Equal(startTime)) && t.Before(endTime) { - inTimeOfDayCache.Store(cacheKey, true) + // inTimeOfDayCache.Store(cacheKey, true) return true } } - inTimeOfDayCache.Store(cacheKey, false) + // inTimeOfDayCache.Store(cacheKey, false) return false } diff --git a/core_test.go b/core_test.go index b87619b..523ef2d 100644 --- a/core_test.go +++ b/core_test.go @@ -49,7 +49,7 @@ func Test_timeCompletion(t *testing.T) { func Test_isInTimeOfDay(t *testing.T) { rand.Seed(time.Now().Unix()) - for k := 0; k < 10; k++ { + for k := 0; k < 300; k++ { rt := rand.Int() % 24 rm := rand.Int() % 60 ti, err := time.ParseInLocation("2006-01-02 15:04:05", fmt.Sprintf("2020-06-08 %.2d:%.2d:00", rt, rm), time.Local) @@ -73,6 +73,7 @@ func Test_isInTimeOfDay(t *testing.T) { if ok != ok2 { t.Fatal("error") } + ok = isInTimeOfDay(ti, TimeArrow{ TimesOnDay: []string{ "17:00-17:10", @@ -108,7 +109,7 @@ func Test_isInTimeOfDay(t *testing.T) { tss = []string{} for i := 0; i < 24; i++ { - if i == 17 { + if i == rt { continue } tss = append(tss, fmt.Sprintf("%d:00-%d:30", i, i))