Ejemplo n.º 1
0
 /**
  * Returns the blackout dates according to the user's timezone.
  *
  * @param   DateTime $date The DateTime object associated with the user's timezone
  * @param   integer $start The blackout start hour
  * @param   integer $end The blackout end hour
  * @return  array The blackout dates
  */
 public function getBlackoutDates($date, $start, $end)
 {
     $start = substr($start, 0, 2);
     $end = substr($end, 0, 2);
     $hour = $date->format('H');
     // if start is AM and end is PM, then use only today
     // if start is AM and end is AM (and end is smaller than start), then use today and tomorrow
     //   - if date is between zero and the end, then use yesterday and today
     // if start is AM and end is AM (and end is bigger than start), then use only today
     // if start is PM and end is PM (and end is smaller than start), then use today and tomorrow
     //   - if date is between zero and the end, then use yesterday and today
     // if start is PM and end is PM (and end is bigger than start), then use only today
     // if start is PM and end is AM, then use today and tomorrow
     //   - if date is between zero and the end, then use yesterday and today
     if (Date_Helper::isAM($start) && Date_Helper::isPM($end)) {
         $first = 0;
         $second = 0;
     }
     if (Date_Helper::isAM($start) && Date_Helper::isAM($end) && $end < $start) {
         if ($hour >= 0 && $hour <= $end) {
             $first = -Date_Helper::DAY;
             $second = 0;
         } else {
             $first = 0;
             $second = Date_Helper::DAY;
         }
     }
     if (Date_Helper::isAM($start) && Date_Helper::isAM($end) && $end > $start) {
         $first = 0;
         $second = 0;
     }
     if (Date_Helper::isPM($start) && Date_Helper::isPM($end) && $end < $start) {
         if ($hour >= 0 && $hour <= $end) {
             $first = -Date_Helper::DAY;
             $second = 0;
         } else {
             $first = 0;
             $second = Date_Helper::DAY;
         }
     }
     if (Date_Helper::isPM($start) && Date_Helper::isPM($end) && $end > $start) {
         $first = 0;
         $second = 0;
     }
     if (Date_Helper::isPM($start) && Date_Helper::isAM($end)) {
         if ($hour >= 0 && $hour <= $end) {
             $first = -Date_Helper::DAY;
             $second = 0;
         } else {
             $first = 0;
             $second = Date_Helper::DAY;
         }
     }
     return array(date('Y-m-d', $date->getTimestamp() + $first), date('Y-m-d', $date->getTimestamp() + $second));
 }