0.2.64 update
This commit is contained in:
+47
-14
@@ -759,7 +759,8 @@ func activeHeroScheduleIDs(schedules []store.HeroSchedule, placement, userID str
|
||||
}
|
||||
matched := []active{}
|
||||
for _, schedule := range schedules {
|
||||
if !schedule.Enabled || (schedule.UserID != "" && schedule.UserID != userID) || now.Before(schedule.StartAt) || !now.Before(schedule.EndAt) {
|
||||
if !schedule.Enabled || (schedule.UserID != "" && schedule.UserID != userID) ||
|
||||
!heroScheduleActiveAt(schedule, now, location) {
|
||||
continue
|
||||
}
|
||||
matchesPlacement := false
|
||||
@@ -775,19 +776,6 @@ func activeHeroScheduleIDs(schedules []store.HeroSchedule, placement, userID str
|
||||
if !matchesPlacement {
|
||||
continue
|
||||
}
|
||||
if len(schedule.Weekdays) > 0 {
|
||||
weekday := int(now.In(location).Weekday())
|
||||
found := false
|
||||
for _, day := range schedule.Weekdays {
|
||||
if day == weekday {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
continue
|
||||
}
|
||||
}
|
||||
matched = append(matched, active{schedule.ItemID, schedule.Priority, schedule.StartAt})
|
||||
}
|
||||
sort.SliceStable(matched, func(i, j int) bool {
|
||||
@@ -803,6 +791,51 @@ func activeHeroScheduleIDs(schedules []store.HeroSchedule, placement, userID str
|
||||
return ids
|
||||
}
|
||||
|
||||
func heroScheduleActiveAt(schedule store.HeroSchedule, now time.Time, location *time.Location) bool {
|
||||
if location == nil {
|
||||
location = time.Local
|
||||
}
|
||||
if schedule.Frequency != "daily" && schedule.Frequency != "weekly" {
|
||||
if now.Before(schedule.StartAt) || !now.Before(schedule.EndAt) {
|
||||
return false
|
||||
}
|
||||
return len(schedule.Weekdays) == 0 || heroScheduleHasWeekday(schedule.Weekdays, int(now.In(location).Weekday()))
|
||||
}
|
||||
start, startErr := time.Parse("15:04", schedule.StartTime)
|
||||
end, endErr := time.Parse("15:04", schedule.EndTime)
|
||||
if startErr != nil || endErr != nil {
|
||||
return false
|
||||
}
|
||||
local := now.In(location)
|
||||
minute := local.Hour()*60 + local.Minute()
|
||||
startMinute := start.Hour()*60 + start.Minute()
|
||||
endMinute := end.Hour()*60 + end.Minute()
|
||||
if startMinute == endMinute {
|
||||
return false
|
||||
}
|
||||
effectiveDay := int(local.Weekday())
|
||||
active := minute >= startMinute && minute < endMinute
|
||||
if startMinute > endMinute {
|
||||
active = minute >= startMinute || minute < endMinute
|
||||
if minute < endMinute {
|
||||
effectiveDay = (effectiveDay + 6) % 7
|
||||
}
|
||||
}
|
||||
if !active || schedule.Frequency == "daily" || len(schedule.Weekdays) == 0 {
|
||||
return active
|
||||
}
|
||||
return heroScheduleHasWeekday(schedule.Weekdays, effectiveDay)
|
||||
}
|
||||
|
||||
func heroScheduleHasWeekday(days []int, weekday int) bool {
|
||||
for _, day := range days {
|
||||
if day == weekday {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// pinnedHeroCandidates resolves policy against the imported catalogue. A deleted or
|
||||
// unsupported id quietly drops out, so an old admin choice can never make Home fail.
|
||||
func (s *Server) pinnedHeroCandidates(ctx context.Context, ids []string) []heroCandidate {
|
||||
|
||||
Reference in New Issue
Block a user