File tree Expand file tree Collapse file tree 4 files changed +14
-10
lines changed
Expand file tree Collapse file tree 4 files changed +14
-10
lines changed Original file line number Diff line number Diff line change @@ -394,21 +394,25 @@ func (r *Ruleset) assume(id string) error {
394394 return r .setAuxiliaryConstraint (constraint )
395395}
396396
397- func (r * Ruleset ) isValidTime ( timestamp * time.Time ) bool {
398- if timestamp == nil {
397+ func (r * Ruleset ) isValidFromTime ( from * time.Time ) bool {
398+ if r . timeDisabled () {
399399 return true
400400 }
401401
402- if len ( r . periodVariables ) == 0 {
402+ if from == nil {
403403 return true
404404 }
405405
406406 for _ , periodVariable := range r .periodVariables {
407- isBeforeEnd := ! timestamp .After (periodVariable .period .To ())
408- if isBeforeEnd {
407+ isValid := ! from .After (periodVariable .period .To ())
408+ if isValid {
409409 return true
410410 }
411411 }
412412
413413 return false
414414}
415+
416+ func (r * Ruleset ) timeDisabled () bool {
417+ return len (r .periodVariables ) == 0
418+ }
Original file line number Diff line number Diff line change @@ -222,7 +222,7 @@ func (c *RulesetCreator) findDependantVariables() []string {
222222
223223func (c * RulesetCreator ) newPeriodVariables () (TimeBoundVariables , error ) {
224224 if c .timeDisabled () {
225- return TimeBoundVariables {} , nil
225+ return nil , nil
226226 }
227227
228228 nonOverlappingPeriods := calculateCompletePeriods (
Original file line number Diff line number Diff line change @@ -374,7 +374,7 @@ func Test_validateVariables_givenUniquePeriod_shouldReturnError(t *testing.T) {
374374 assert .Error (t , err )
375375}
376376
377- func Test_RuleSet_isValidTime (t * testing.T ) {
377+ func Test_RuleSet_isValidFromTime (t * testing.T ) {
378378 timestamp := fake .New [time.Time ]()
379379 before := timestamp .Add (- 1 * time .Hour )
380380 after := timestamp .Add (1 * time .Hour )
@@ -445,7 +445,7 @@ func Test_RuleSet_isValidTime(t *testing.T) {
445445
446446 for _ , tt := range cases {
447447 t .Run (tt .name , func (t * testing.T ) {
448- got := tt .ruleset .isValidTime (tt .timestamp )
448+ got := tt .ruleset .isValidFromTime (tt .timestamp )
449449 assert .Equal (t , tt .want , got )
450450 })
451451 }
Original file line number Diff line number Diff line change @@ -192,10 +192,10 @@ func updateSolveError(
192192) error {
193193 noSolutionFound := errors .Is (err , puanerror .NoSolutionFound )
194194 if noSolutionFound {
195- invalidTime := ! ruleset .isValidTime (from )
195+ invalidTime := ! ruleset .isValidFromTime (from )
196196 if invalidTime {
197197 return errors .Errorf (
198- "%wFrom '%s' is not valid for the ruleset" ,
198+ "%w: from '%s' is not valid for the ruleset" ,
199199 puanerror .InvalidArgument ,
200200 from ,
201201 )
You can’t perform that action at this time.
0 commit comments