u 3 years ago
parent
commit
ad92af2d6e
  1. 21
      core.go
  2. 5
      core_test.go

21
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
}

5
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))

Loading…
Cancel
Save