Last active
July 23, 2018 14:44
-
-
Save cruzccl/361add4e53e14beb7d422a77b76accfa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// IsValid determines if the rating plan covers a continous period of time | |
func (rp *RatingPlan) isContinous() bool { | |
weekdays := make([]int, 7) | |
for _, dr := range rp.DestinationRates { | |
var tmgs []*RITiming | |
for _, tmg := range dr { | |
tmgs = append(tmgs, rp.Timings[tmg.Timing]) | |
} | |
continuous := false | |
for _, tm := range tmgs { | |
// if it is a blank timing than it will match all | |
if tm.IsBlank() { | |
continuous = true | |
break | |
} | |
// skip the special timings (for specific dates) | |
if len(tm.Years) != 0 || len(tm.Months) != 0 || len(tm.MonthDays) != 0 { | |
continue | |
} | |
// if the startime is not midnight than is an extra time | |
if tm.StartTime != "00:00:00" { | |
continue | |
} | |
//check if all weekdays are covered | |
for _, wd := range tm.WeekDays { | |
weekdays[wd] = 1 | |
} | |
allWeekdaysCovered := true | |
for _, wd := range weekdays { | |
if wd != 1 { | |
allWeekdaysCovered = false | |
break | |
} | |
} | |
if allWeekdaysCovered { | |
continuous = true | |
break | |
} | |
} | |
if (!continuous) { | |
return false | |
} | |
} | |
return true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment