Browse Source

vnrw

master
甘昌盛 1 day ago
parent
commit
cbd5e08f0f
  1. 70
      core.go

70
core.go

@ -538,3 +538,73 @@ func (th *TimeArrowHelper) GetHitTimeArrow(t time.Time, group string, expandTags
return nil, nil
}
func GetHitTimeArrowV3(ta TimeArrows, t time.Time, group string, expandTags ...string) (*TimeArrow, error) {
sort.Slice(ta, func(i, j int) bool {
return ta[i].Weights > ta[j].Weights
})
for e := range ta {
if ta[e].Type != TimeArrowTypeInHolidays &&
ta[e].Type != TimeArrowTypeAtLastDayHolidays &&
ta[e].Type != TimeArrowTypeDayOfWeek &&
ta[e].Type != TimeArrowTypeDayOfMonth &&
ta[e].Type != TimeArrowTypeDateSlice &&
ta[e].Type != TimeArrowTypePriorToDayHolidays {
continue
}
//当天具体时间判断
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]) {
return &ta[e], nil
}
break
case TimeArrowTypeDayOfMonth:
//一月中某一天是否判定
if isInDayOfMonth(t, ta[e]) {
return &ta[e], nil
}
break
case TimeArrowTypeDateSlice:
//一月中某一天是否判定
if isInDateSlice(t, ta[e]) {
return &ta[e], nil
}
break
case TimeArrowTypeAtLastDayHolidays:
//节假日最后一天
if isInAtLastDayHolidays(t) {
return &ta[e], nil
}
break
case TimeArrowTypePriorToDayHolidays:
//节假日前一天
if isInPriorToDayHolidays(t) {
return &ta[e], nil
}
break
case TimeArrowTypeInHolidays:
//节假日
if isInHolidays(t) {
return &ta[e], nil
}
break
// default:
// log.Println("类型错误:", ta[e].Type)
}
}
return nil, nil
}
Loading…
Cancel
Save