|
@ -112,6 +112,11 @@ func timeCompletion(a string) string { |
|
|
for len(sc) < 3 { |
|
|
for len(sc) < 3 { |
|
|
sc = append(sc, "00") |
|
|
sc = append(sc, "00") |
|
|
} |
|
|
} |
|
|
|
|
|
for i := range sc { |
|
|
|
|
|
if len(sc[i]) == 1 { |
|
|
|
|
|
sc[i] = "0" + sc[i] |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
ret := strings.Join(sc, ":") |
|
|
ret := strings.Join(sc, ":") |
|
|
timeCompletionCache.Store(a, ret) |
|
|
timeCompletionCache.Store(a, ret) |
|
|
return ret |
|
|
return ret |
|
@ -127,16 +132,56 @@ func isInDayOfMonth(t time.Time, ta TimeArrow) bool { |
|
|
return false |
|
|
return false |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var inTimeOfDayCache sync.Map |
|
|
|
|
|
|
|
|
func isInTimeOfDay(t time.Time, ta TimeArrow) bool { |
|
|
func isInTimeOfDay(t time.Time, ta TimeArrow) bool { |
|
|
|
|
|
if len(ta.TimesOnDay) == 0 { |
|
|
|
|
|
return true |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
tfdate := t.Format("15:04:05") |
|
|
|
|
|
|
|
|
|
|
|
cacheKey := fmt.Sprint(tfdate, strings.Join(ta.TimesOnDay, "|")) |
|
|
|
|
|
ret, ok := inTimeOfDayCache.Load(cacheKey) |
|
|
|
|
|
if ok { |
|
|
|
|
|
return ret.(bool) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for k := range ta.TimesOnDay { |
|
|
|
|
|
tsp := strings.Split(ta.TimesOnDay[k], "-") |
|
|
|
|
|
if len(tsp) < 2 { |
|
|
|
|
|
log.Println("必须为时间段:", ta.TimesOnDay[k]) |
|
|
|
|
|
continue |
|
|
|
|
|
} |
|
|
|
|
|
start, end := tsp[0], tsp[1] |
|
|
|
|
|
start = timeCompletion(start) |
|
|
|
|
|
end = timeCompletion(end) |
|
|
|
|
|
fmt.Println("ssee", start, end, tfdate) |
|
|
|
|
|
if start <= tfdate && tfdate < end { |
|
|
|
|
|
inTimeOfDayCache.Store(cacheKey, true) |
|
|
|
|
|
return true |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
inTimeOfDayCache.Store(cacheKey, false) |
|
|
|
|
|
return false |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
func isInTimeOfDay2(t time.Time, ta TimeArrow) bool { |
|
|
if len(ta.TimesOnDay) == 0 { |
|
|
if len(ta.TimesOnDay) == 0 { |
|
|
return true |
|
|
return true |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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") |
|
|
tfdate := t.Format("2006-01-02") |
|
|
|
|
|
|
|
|
parseInLocationCache := map[string]time.Time{} |
|
|
|
|
|
var err error |
|
|
|
|
|
|
|
|
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 { |
|
|
for k := range ta.TimesOnDay { |
|
|
tsp := strings.Split(ta.TimesOnDay[k], "-") |
|
|
tsp := strings.Split(ta.TimesOnDay[k], "-") |
|
|
if len(tsp) < 2 { |
|
|
if len(tsp) < 2 { |
|
@ -149,20 +194,14 @@ func isInTimeOfDay(t time.Time, ta TimeArrow) bool { |
|
|
start = timeCompletion(start) |
|
|
start = timeCompletion(start) |
|
|
end = timeCompletion(end) |
|
|
end = timeCompletion(end) |
|
|
|
|
|
|
|
|
|
|
|
//tfdate为当天日期
|
|
|
startTimeKey := fmt.Sprintf("%s %s", tfdate, start) |
|
|
startTimeKey := fmt.Sprintf("%s %s", tfdate, start) |
|
|
startTime, ok := parseInLocationCache[startTimeKey] |
|
|
|
|
|
if !ok { |
|
|
|
|
|
startTime, err = time.ParseInLocation("2006-01-02 15:04:05", startTimeKey, time.Local) |
|
|
|
|
|
parseInLocationCache[startTimeKey] = startTime |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
log.Println("时间段开始时间格式错误", start) |
|
|
|
|
|
continue |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
if startTime.IsZero() { |
|
|
|
|
|
log.Println("时间段开始时间格式错误", start) |
|
|
|
|
|
continue |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
startTime, _ := time.ParseInLocation("2006-01-02 15:04:05", startTimeKey, time.Local) |
|
|
|
|
|
|
|
|
|
|
|
if startTime.IsZero() { |
|
|
|
|
|
log.Println("时间段开始时间格式错误", start) |
|
|
|
|
|
continue |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if end == "24" || end == "24:00" || end == "24:00:00" { |
|
|
if end == "24" || end == "24:00" || end == "24:00:00" { |
|
@ -170,19 +209,11 @@ func isInTimeOfDay(t time.Time, ta TimeArrow) bool { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
endTimeKey := fmt.Sprintf("%s %s", tfdate, end) |
|
|
endTimeKey := fmt.Sprintf("%s %s", tfdate, end) |
|
|
endTime, ok := parseInLocationCache[endTimeKey] |
|
|
|
|
|
if !ok { |
|
|
|
|
|
endTime, err = time.ParseInLocation("2006-01-02 15:04:05", endTimeKey, time.Local) |
|
|
|
|
|
parseInLocationCache[endTimeKey] = endTime |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
log.Println("时间段结束时间格式错误", end) |
|
|
|
|
|
continue |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
if endTime.IsZero() { |
|
|
|
|
|
log.Println("时间段结束时间格式错误", end) |
|
|
|
|
|
continue |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
endTime, _ := time.ParseInLocation("2006-01-02 15:04:05", endTimeKey, time.Local) |
|
|
|
|
|
if endTime.IsZero() { |
|
|
|
|
|
log.Println("时间段结束时间格式错误", end) |
|
|
|
|
|
continue |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if startTime.Unix() > endTime.Unix() { |
|
|
if startTime.Unix() > endTime.Unix() { |
|
@ -191,9 +222,11 @@ func isInTimeOfDay(t time.Time, ta TimeArrow) bool { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (t.After(startTime) || t.Equal(startTime)) && t.Before(endTime) { |
|
|
if (t.After(startTime) || t.Equal(startTime)) && t.Before(endTime) { |
|
|
|
|
|
inTimeOfDayCache.Store(cacheKey, true) |
|
|
return true |
|
|
return true |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
inTimeOfDayCache.Store(cacheKey, false) |
|
|
return false |
|
|
return false |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|