From 428e4156164a41167bc78b2609ff805f1a42fe13 Mon Sep 17 00:00:00 2001 From: TwinProduction Date: Mon, 27 Sep 2021 00:11:42 -0400 Subject: [PATCH] Fix issue with under maintenance --- config/maintenance/maintenance.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/config/maintenance/maintenance.go b/config/maintenance/maintenance.go index 29da9294..d34f6a99 100644 --- a/config/maintenance/maintenance.go +++ b/config/maintenance/maintenance.go @@ -3,7 +3,6 @@ package maintenance import ( "errors" "fmt" - "sort" "strconv" "strings" "time" @@ -98,7 +97,7 @@ func (c Config) IsUnderMaintenance() bool { now := time.Now().UTC() dayWhereMaintenancePeriodWouldStart := now.Add(-c.Duration).Truncate(24 * time.Hour) hasMaintenanceEveryDay := len(c.Every) == 0 - hasMaintenancePeriodScheduledForThatWeekday := sort.SearchStrings(c.Every, dayWhereMaintenancePeriodWouldStart.Weekday().String()) != len(c.Every) + hasMaintenancePeriodScheduledForThatWeekday := c.hasDay(dayWhereMaintenancePeriodWouldStart.Weekday().String()) if !hasMaintenanceEveryDay && !hasMaintenancePeriodScheduledForThatWeekday { // The day when the maintenance period would start is not scheduled // to have any maintenance, so we can just return false. @@ -109,6 +108,15 @@ func (c Config) IsUnderMaintenance() bool { return now.After(startOfMaintenancePeriod) && now.Before(endOfMaintenancePeriod) } +func (c Config) hasDay(day string) bool { + for _, d := range c.Every { + if d == day { + return true + } + } + return false +} + func hhmmToDuration(s string) (time.Duration, error) { if len(s) != 5 { return 0, errInvalidMaintenanceStartFormat