public function hook_calendar($userId)
 {
     $date = new w2p_Utilities_Date(w2PgetParam($_GET, 'date', null));
     $date->setTime(0, 0, 0);
     $start = $date->duplicate();
     $end = $date->duplicate();
     $view = w2PgetParam($_GET, 'a', 'month_view');
     switch ($view) {
         case 'day_view':
             break;
         case 'week_view':
             $end->addDays(6);
             break;
         case 'index':
         case 'month_view':
             $start->setDay(1);
             $end->setDay($date->getDaysInMonth());
             break;
         case 'year_view':
             $start->setMonth(1);
             $start->setDay(1);
             $end->setMonth(12);
             $end->setDay(31);
             break;
     }
     $end->setTime(23, 59, 59);
     $holidays = HolidayFunctions::getHolidaysForDatespan($start, $end, $userId);
     $itemsList = array();
     foreach ($holidays as $i => $holiday) {
         $date = $holiday['startDate'];
         $end = $holiday['endDate'];
         while (!$date->after(clone $end)) {
             $itemsList[] = array('id' => $holiday['id'], 'name' => $holiday['name'], 'startDate' => $date->format(FMT_TIMESTAMP_DATE), 'endDate' => $date->format(FMT_TIMESTAMP_DATE), 'description' => $holiday['description']);
             $date = $date->getNextDay();
         }
     }
     return $itemsList;
 }
예제 #2
0
$first_time->setTime(0, 0, 0);
// if Sunday is the 1st, we don't need to go back
// as that's the first day shown on the calendar
if ($first_time->getDayOfWeek() != 0) {
    $last_day_of_previous_month = $first_time->getPrevDay();
    $day_of_previous_month = $last_day_of_previous_month->getDayOfWeek();
    $seconds_to_sub_in_previous_month = 86400 * $day_of_previous_month;
    // need to cast it to int because Pear::Date_Span::set down the line
    // fails to set the seconds correctly
    $last_day_of_previous_month->subtractSeconds((int) $seconds_to_sub_in_previous_month);
    $first_time->setDay($last_day_of_previous_month->getDay());
    $first_time->setMonth($last_day_of_previous_month->getMonth());
    $first_time->setYear($last_day_of_previous_month->getYear());
}
$last_time = new w2p_Utilities_Date($date);
$last_time->setDay($date->getDaysInMonth());
$last_time->setTime(23, 59, 59);
// if Saturday is the last day of month, we don't need to go forward
// as that's the last day shown on the calendar
if ($last_time->getDayOfWeek() != 6) {
    $first_day_of_next_month = $last_time->getNextDay();
    $day_of_next_month = $first_day_of_next_month->getDayOfWeek();
    $seconds_to_add_in_next_month = 86400 * $day_of_next_month;
    // need to cast it to int because Pear::Date_Span::set down the line
    // fails to set the seconds correctly
    $first_day_of_next_month->addSeconds((int) $seconds_to_add_in_next_month);
    $last_time->setDay($first_day_of_next_month->getDay());
    $last_time->setMonth($first_day_of_next_month->getMonth());
    $last_time->setYear($first_day_of_next_month->getYear());
}
$links = array();
예제 #3
0
 /**
  * Tests getDaysInMonth
  */
 public function testGetDaysInMonth()
 {
     $date = new w2p_Utilities_Date('2010-11-05 11:00:00');
     $this->assertEquals(30, $date->getDaysInMonth());
     $date->setMonth(12);
     $this->assertEquals(31, $date->getDaysInMonth());
 }