public function __construct(Horde_Date $date) { $week = $date->weekOfYear(); $year = $date->year; if (!$GLOBALS['prefs']->getValue('week_start_monday') && $date->dayOfWeek() == Horde_Date::DATE_SUNDAY) { ++$week; } if ($week > 51 && $date->month == 1) { --$year; } elseif ($week == 1 && $date->month == 12) { ++$year; } $this->year = $year; $this->week = $week; $day = Horde_Date_Utils::firstDayOfWeek($week, $year); if (!isset($this->startDay)) { if ($GLOBALS['prefs']->getValue('week_start_monday')) { $this->startDay = Horde_Date::DATE_MONDAY; $this->endDay = Horde_Date::DATE_SUNDAY + 7; } else { $day->mday--; $this->startDay = Horde_Date::DATE_SUNDAY; $this->endDay = Horde_Date::DATE_SATURDAY; } } $this->startDate = new Horde_Date($day); for ($i = $this->startDay; $i <= $this->endDay; ++$i) { $this->days[$i] = new Kronolith_View_Day($day, array()); $day->mday++; } $endDate = new Horde_Date($day); try { $allevents = Kronolith::listEvents($this->startDate, $endDate); } catch (Exception $e) { $GLOBALS['notification']->push($e, 'horde.error'); $allevents = array(); } for ($i = $this->startDay; $i <= $this->endDay; ++$i) { $date_stamp = $this->days[$i]->dateString(); $this->days[$i]->events = isset($allevents[$date_stamp]) ? $allevents[$date_stamp] : array(); } $this->sidebyside = $this->days[$this->startDay]->sidebyside; $this->_currentCalendars = $this->days[$this->startDay]->currentCalendars; $this->slotsPerHour = $this->days[$this->startDay]->slotsPerHour; $this->slotsPerDay = $this->days[$this->startDay]->slotsPerDay; $this->slotLength = $this->days[$this->startDay]->slotLength; }
/** * Returns the number of weeks in the given year (52 or 53). * * @param integer $year The year to count the number of weeks in. * * @return integer $numWeeks The number of weeks in $year. */ public static function weeksInYear($year) { // Find the last Thursday of the year. $date = new Horde_Date($year . '-12-31'); while ($date->dayOfWeek() != self::DATE_THURSDAY) { --$date->mday; } return $date->weekOfYear(); }