for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Recurrence\Constraint;
use Recurrence\Model\Recurrence;
/**
* Class ExcludeWeekendConstraint
* @package Recurrence\Constraint
*/
class ExcludeWeekendConstraint implements RecurrenceConstraintInterface
{
* @param Recurrence $recurrence
* @param \Datetime $datetime
* @return \Datetime
public function apply(Recurrence $recurrence, \Datetime $datetime)
if ($this->isWeekend($datetime)) {
// Add 1 or 2 days to skip weekend (we didn't use `next monday` pattern of \Datetime::format cause it remove time)
$days = (7 - (int) $datetime->format('N') + 1);
$datetime->modify(sprintf('+%d days', $days));
}
return $datetime;
* @return bool
private function isWeekend($datetime) {
return ((int) $datetime->format('N') >= 6);