/** * DaysOfWeeks constructor. * @param Period $periode * @param GestyScheduler $scheduler */ public function __construct(Period $periode, GestyScheduler $scheduler) { $this->periode = $periode; foreach ($this->periode->getDayIterator() as $currentDay) { $d = new Day($currentDay); if (!$scheduler->isDayOff($currentDay, ActivityType::TAP)) { $this->list_jours_tap[$d->getWeekDay()][] = $currentDay->format('Y-m-d'); } if (!$scheduler->isDayOff($currentDay, ActivityType::GARDERIE_MORNING)) { $this->list_jours_garderie[$d->getWeekDay() . '-1'][] = $currentDay->format('Y-m-d'); } if (!$scheduler->isDayOff($currentDay, ActivityType::GARDERIE_EVENING)) { $this->list_jours_garderie[$d->getWeekDay() . '-2'][] = $currentDay->format('Y-m-d'); } } }
/** * @param $activityTypeConstant * @param \DateTimeInterface $dateDay * @return bool */ public static function isDayOff($activityTypeConstant, \DateTimeInterface $dateDay) { $d = new Day($dateDay); $daysOff = self::$daysOfWeekOff[$activityTypeConstant]; return \in_array($d->getWeekDay(), $daysOff); }
/** * @param \DateTimeInterface $date * @param array $options with index to which the weekstat will be assigned. * @return bool */ public function isDayOff(\DateTimeInterface $date, array $options) { if (\in_array($date, $this->datesDayOff)) { return true; } foreach ($this->periodsDayOff as $periodDayOff) { if ($periodDayOff->isIncluded($date)) { return true; } } if (isset($options['index'])) { $index = $options['index']; $d = new Day($date); if (\in_array($d->getWeekDay(), $this->weekUsualDaysOff[$index])) { return true; } } return false; }
/** * @covers ::getWeekDay * * @dataProvider provideValidWeekDays * @param Day $day * @param string $expectedWeekDay */ public function testGetWeekDayReturnCorrectDay(Day $day, $expectedWeekDay) { $this->assertEquals($expectedWeekDay, $day->getWeekDay()); }