示例#1
0
 /**
  * Is Active
  * determines if current Holiday is active
  *
  * @param     DateTime  $now    The DateTime representing the current time. Can be modified to check whether
  *                              the holiday will be active or has been active at a certain time.
  *                              Default is the current time
  *
  * @return    bool              Whether the holiday has been active, will be active, is active at the provided time
  */
 public function isActive(DateTime $now = null)
 {
     if ($now === null) {
         $now = Dates::getNow();
     }
     return $this->dateStart <= $now and $this->dateEnd >= $now;
 }
示例#2
0
 /**
  * Renders an Irregular Opening Item for Overview table
  *
  * @param     IrregularOpening  $io           The Irregular Opening to show
  * @param     array             $attributes   The shortcode attributes
  */
 public static function renderIrregularOpening(IrregularOpening $io, array $attributes)
 {
     $name = $io->getName();
     $date = $io->getTimeStart()->format(Dates::getDateFormat());
     $heading = $attributes['hide_io_date'] ? $name : sprintf('%s (%s)', $name, $date);
     $now = Dates::getNow();
     $highlighted = ($attributes['highlight'] == 'period' and $io->getTimeStart() <= $now and $now <= $io->getTimeEnd()) ? $attributes['highlighted_period_class'] : null;
     echo '<span class="op-period-time irregular-opening ' . $highlighted . '">' . $heading . '</span>';
     $time_start = $io->getTimeStart()->format($attributes['time_format']);
     $time_end = $io->getTimeEnd()->format($attributes['time_format']);
     $period = sprintf('%s – %s', $time_start, $time_end);
     echo '<span class="op-period-time ' . $highlighted . ' ' . $attributes['span_period_classes'] . '">' . $period . '</span>';
 }
示例#3
0
 /**
  * Checks whether Period is currently open regardless of Holidays and IrregularOpenings
  *
  * @param     DateTime  $now
  * @return    bool      Whether Period is currently open regardless of Holidays and SpecialOpenings
  */
 public function isOpenStrict(DateTime $now = null)
 {
     if (!$now instanceof DateTime) {
         $now = Dates::getNow();
     }
     $today = (int) $now->format('N') - 1;
     $startDay = $this->weekday;
     $endDay = (int) $this->timeEnd->format('N') - 1;
     if ($today !== $startDay and $today !== $endDay) {
         return false;
     }
     $timeStart = (int) $this->timeStart->format('Hi');
     $timeEnd = (int) $this->timeEnd->format('Hi');
     $timeNow = (int) $now->format('Hi');
     if (!$this->spansTwoDays) {
         return $timeStart <= $timeNow and $timeNow <= $timeEnd;
     }
     if ($today == $startDay) {
         return $timeStart <= $timeNow;
     }
     return $timeNow <= $timeEnd;
 }
 /**
  * Factory for dummy IO
  * @return    IrregularOpening  An IO dummy
  */
 public static function createDummy()
 {
     $now = Dates::getNow();
     return new IrregularOpening('', $now->format(Dates::STD_DATE_FORMAT), '00:00', '00:00', true);
 }
示例#5
0
 /**
  * Returns the first active holiday on the specified weekday
  * @param     int       $weekday  weekday number 0-6
  * @param     DateTime  $now      custom DateTime. The next day of the specified weekday with be used
  * @return    Holiday             The first active holiday on the specified weekday
  */
 public function getActiveHolidayOnWeekday($weekday, DateTime $now = null)
 {
     if ($now == null) {
         $now = Dates::getNow();
     }
     $now = clone $now;
     $date = Dates::applyWeekContext($now, $weekday, $now);
     return $this->getActiveHoliday($date);
 }