Rule To Validate Date Range


I have a date range (start end enddate) in my vacation model.

I would like to validate that a new vacation of one user does not overlap with an already existing vacation.

Is it possible to do this with a rule and if so, how?

If it’s not possible or hard to implement I would add the logic to the action but I prefer doing this with a rule.

You can write your own custom validation rule for this.

As said Roman, add a custom rule, in the array of rules add:

[code]array('start_date', 'notOverlap')


And add a function

public function notOverlap()


   if (search for other overlapping vacations)

      $this->addError('create_date', 'Your  vacation is overlapped with others!')