Ejemplo n.º 1
0
 /**
  * Returns the blackout dates according to the user's timezone.
  *
  * @access  public
  * @param   object $user The Date 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
  */
 function getBlackoutDates($user, $start, $end)
 {
     $start = substr($start, 0, 2);
     $end = substr($end, 0, 2);
     // 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_API::isAM($start) && Date_API::isPM($end)) {
         $first = 0;
         $second = 0;
     }
     if (Date_API::isAM($start) && Date_API::isAM($end) && $end < $start) {
         if ($user->getHour() >= 0 && $user->getHour() <= $end) {
             $first = -DAY;
             $second = 0;
         } else {
             $first = 0;
             $second = DAY;
         }
     }
     if (Date_API::isAM($start) && Date_API::isAM($end) && $end > $start) {
         $first = 0;
         $second = 0;
     }
     if (Date_API::isPM($start) && Date_API::isPM($end) && $end < $start) {
         if ($user->getHour() >= 0 && $user->getHour() <= $end) {
             $first = -DAY;
             $second = 0;
         } else {
             $first = 0;
             $second = DAY;
         }
     }
     if (Date_API::isPM($start) && Date_API::isPM($end) && $end > $start) {
         $first = 0;
         $second = 0;
     }
     if (Date_API::isPM($start) && Date_API::isAM($end)) {
         if ($user->getHour() >= 0 && $user->getHour() <= $end) {
             $first = -DAY;
             $second = 0;
         } else {
             $first = 0;
             $second = DAY;
         }
     }
     return array(date('Y-m-d', $user->getDate(DATE_FORMAT_UNIXTIME) + $first), date('Y-m-d', $user->getDate(DATE_FORMAT_UNIXTIME) + $second));
 }