public_host 4 years ago
parent
commit
866d55a72a
  1. 63
      core.go

63
core.go

@ -295,6 +295,69 @@ type TimeArrowHelper struct {
GetData func(group string) (TimeArrows, error)
}
func (th *TimeArrowHelper) CallHitTimeArrow(t time.Time, group string, call func(*TimeArrow), expandTags ...string) error {
ta, err := th.GetData(group)
if err != nil {
return err
}
sort.Slice(ta, func(i, j int) bool {
return ta[i].Weights > ta[j].Weights
})
for e := range ta {
//当天具体时间判断
if !isInTimeOfDay(t, ta[e]) {
continue
}
//扩展标签判断
if !isInExpandTags(ta[e], strings.Join(expandTags, "-")) {
continue
}
switch ta[e].Type {
case TimeArrowTypeDayOfWeek:
//一周中某一天是否判定
if isInWeekOfDay(t, ta[e]) {
call(&ta[e])
}
break
case TimeArrowTypeDayOfMonth:
//一月中某一天是否判定
if isInDayOfMonth(t, ta[e]) {
call(&ta[e])
}
break
case TimeArrowTypeDateSlice:
//一月中某一天是否判定
if isInDateSlice(t, ta[e]) {
call(&ta[e])
}
break
case TimeArrowTypeAtLastDayHolidays:
//节假日最后一天
if isInAtLastDayHolidays(t) {
call(&ta[e])
}
break
case TimeArrowTypePriorToDayHolidays:
//节假日前一天
if isInPriorToDayHolidays(t) {
call(&ta[e])
}
break
case TimeArrowTypeInHolidays:
//节假日
if isInHolidays(t) {
call(&ta[e])
}
break
default:
log.Println("类型错误:", ta[e].Type)
}
}
return nil
}
func (th *TimeArrowHelper) GetHitTimeArrow(t time.Time, group string, expandTags ...string) (*TimeArrow, error) {
ta, err := th.GetData(group)
if err != nil {

Loading…
Cancel
Save