Compares this date to another date object to see which one is
greater (later). Assumes that the dates are in the same
timezone.
public compareDate ( mixed $other ) : integer | ||
$other | mixed | The date to compare to. |
return | integer | == 0 if they are on the same date >= 1 if $this is greater (later) <= -1 if $other is greater (later) |
/** * Search the database for call detail records, taking permissions into * consideration. * * @return array [0] contains summary statistics; [1] is an array of the * actual call records. * @throws Operator_Exception */ public function getRecords($start, $end, $accountcode = null, $dcontext = null, $rowstart = 0, $rowlimit = 100) { // Start Date if (!is_a($start, 'Horde_Date')) { $start = new Horde_Date($start); } // End Date if (!is_a($end, 'Horde_Date')) { $end = new Horde_Date($end); } if ($start->compareDate($end) > 0) { throw new Operator_Exception(_("\"Start\" date must be on or before \"End\" date.")); } if (empty($accountcode) || $accountcode == '%') { $permentry = 'operator:accountcodes'; } else { $permentry = 'operator:accountcodes:' . $accountcode; } $perms = $GLOBALS['injector']->getInstance('Horde_Perms'); if ($GLOBALS['registry']->isAdmin() || $perms->hasPermission('operator:accountcodes', $GLOBALS['registry']->getAuth(), Horde_Perms::READ) || $perms->hasPermission($permentry, $GLOBALS['registry']->getAuth(), Horde_Perms::READ)) { return $this->_getRecords($start, $end, $accountcode, $dcontext, $rowstart, $rowlimit); } throw new Operator_Exception(_("You do not have permission to view call detail records for that account code.")); }
/** * @return string The time range of the event ("All Day", "1:00pm-3:00pm", * "08:00-22:00"). */ public function getTimeRange() { if ($this->isAllDay()) { return _("All day"); } elseif (($cmp = $this->start->compareDate($this->end)) > 0) { $df = $GLOBALS['prefs']->getValue('date_format'); if ($cmp > 0) { return $this->end->strftime($df) . '-' . $this->start->strftime($df); } else { return $this->start->strftime($df) . '-' . $this->end->strftime($df); } } else { $twentyFour = $GLOBALS['prefs']->getValue('twentyFour'); return $this->start->format($twentyFour ? 'G:i' : 'g:ia') . '-' . $this->end->format($twentyFour ? 'G:i' : 'g:ia'); } }
private function _getEvents($dh, $startDate, $endDate) { $events = array(); for ($date = new Horde_Date($startDate); $date->compareDate($endDate) <= 0; $date->mday++) { $holidays = $dh->getHolidayForDate($date->format('Y-m-d'), null, true); if (Date_Holidays::isError($holidays)) { Horde::log(sprintf('Unable to retrieve list of holidays from %s to %s', (string) $startDate, (string) $endDate), __FILE__, __LINE__); continue; } if (is_null($holidays)) { continue; } foreach ($holidays as $holiday) { $event = new Kronolith_Event_Holidays($this, $holiday); $events[] = $event; } } return $events; }
/** * Returns whether any tasks in the list are overdue. * * @return boolean True if any task or sub tasks are overdue. */ public function childrenOverdue() { if (!empty($this->due)) { $due = new Horde_Date($this->due); if ($due->compareDate(new Horde_Date(time())) <= 0) { return true; } } foreach ($this->children as $task) { if ($task->childrenOverdue()) { return true; } } return false; }
/** * Returns a list of birthday or anniversary hashes from this source for a * certain period. * * @param Horde_Date $start The start date of the valid period. * @param Horde_Date $end The end date of the valid period. * @param string $category The timeObjects category to return. * * @return array A list of timeObject hashes. * @throws Turba Exception */ public function listTimeObjects(Horde_Date $start, Horde_Date $end, $category) { try { $res = $this->getTimeObjectTurbaList($start, $end, $category); } catch (Turba_Exception $e) { /* Try the default implementation before returning an error */ $res = $this->_getTimeObjectTurbaListFallback($start, $end, $category); } $t_objects = array(); while ($ob = $res->next()) { $t_object = $ob->getValue($category); if (empty($t_object)) { continue; } try { $t_object = new Horde_Date($t_object); } catch (Horde_Date_Exception $e) { continue; } if ($t_object->compareDate($end) > 0) { continue; } $t_object_end = new Horde_Date($t_object); ++$t_object_end->mday; $key = $ob->getValue('__key'); // Calculate the age of the time object if ($start->year == $end->year || $end->year == 9999) { $age = $start->year - $t_object->year; } elseif ($t_object->month <= $end->month) { // t_object must be in later year $age = $end->year - $t_object->year; } else { // t_object must be in earlier year $age = $start->year - $t_object->year; } $title = sprintf(_("%d. %s of %s"), $age, $GLOBALS['attributes'][$category]['label'], $ob->getValue('name')); $t_objects[] = array('id' => $key, 'title' => $title, 'start' => sprintf('%d-%02d-%02dT00:00:00', $t_object->year, $t_object->month, $t_object->mday), 'end' => sprintf('%d-%02d-%02dT00:00:00', $t_object_end->year, $t_object_end->month, $t_object_end->mday), 'recurrence' => array('type' => Horde_Date_Recurrence::RECUR_YEARLY_DATE, 'interval' => 1), 'params' => array('source' => $this->_name, 'key' => $key), 'link' => Horde::url('contact.php', true)->add(array('source' => $this->_name, 'key' => $key))->setRaw(true)); } return $t_objects; }
/** * Adds an event to all the days it covers. * * @param array $result The current result list. * @param Kronolith_Event $event An event object. * @param Horde_Date $eventStart The event's start at the actual * recurrence. * @param Horde_Date $eventEnd The event's end at the actual recurrence. * @param boolean $json Store the results of the events' toJson() * method? */ public static function addCoverDates(&$results, $event, $eventStart, $eventEnd, $json) { $loopDate = new Horde_Date($eventStart->year, $eventStart->month, $eventStart->mday); $allDay = $event->isAllDay(); while ($loopDate->compareDateTime($eventEnd) <= 0) { if (!$allDay || $loopDate->compareDateTime($eventEnd) != 0) { $addEvent = clone $event; $addEvent->start = $eventStart; $addEvent->end = $eventEnd; if ($loopDate->compareDate($eventStart) != 0) { $addEvent->first = false; } if ($loopDate->compareDate($eventEnd) != 0) { $addEvent->last = false; } if ($addEvent->recurs() && $addEvent->recurrence->hasCompletion($loopDate->year, $loopDate->month, $loopDate->mday)) { $addEvent->status = Kronolith::STATUS_CANCELLED; } $results[$loopDate->dateString()][$addEvent->id] = $json ? $addEvent->toJson($allDay) : $addEvent; } $loopDate->mday++; } }
public function isTomorrow() { $date = new Horde_Date(array('month' => $this->month, 'mday' => $this->mday - 1, 'year' => $this->year)); return $date->compareDate(new Horde_Date(mktime(0, 0, 0))) == 0; }
/** * Return message changes from the specified mailbox. * * @param Horde_ActiveSync_Folder_Imap $folder The folder object. * @param array $options Additional options: * - sincedate: (integer) Timestamp of earliest message to retrieve. * DEFAULT: 0 (Don't filter). * - protocolversion: (float) EAS protocol version to support. * DEFAULT: none REQUIRED * - softdelete: (boolean) If true, calculate SOFTDELETE data. * @since 2.8.0 * * @return Horde_ActiveSync_Folder_Imap The folder object, containing any * change instructions for the device. * * @throws Horde_ActiveSync_Exception_FolderGone, * Horde_ActiveSync_Exception, Horde_ActiveSync_Exception_StaleState */ public function getMessageChanges(Horde_ActiveSync_Folder_Imap $folder, array $options = array()) { $imap = $this->_getImapOb(); $mbox = new Horde_Imap_Client_Mailbox($folder->serverid()); // Note: non-CONDSTORE servers will return a highestmodseq of 0 $status_flags = Horde_Imap_Client::STATUS_HIGHESTMODSEQ | Horde_Imap_Client::STATUS_UIDVALIDITY | Horde_Imap_Client::STATUS_UIDNEXT_FORCE | Horde_Imap_Client::STATUS_MESSAGES | Horde_Imap_Client::STATUS_FORCE_REFRESH; try { $status = $imap->status($mbox, $status_flags); } catch (Horde_Imap_Client_Exception $e) { // If we can't status the mailbox, assume it's gone. throw new Horde_ActiveSync_Exception_FolderGone($e); } $this->_logger->info(sprintf('[%s] IMAP status: %s', $this->_procid, serialize($status))); $flags = array(); $categories = array(); $modseq = $status[Horde_ActiveSync_Folder_Imap::HIGHESTMODSEQ]; if ($modseq && $folder->modseq() > 0 && $folder->modseq() < $modseq) { $this->_logger->info(sprintf('[%s] CONDSTORE and CHANGES', $this->_procid)); $folder->checkValidity($status); $query = new Horde_Imap_Client_Fetch_Query(); $query->modseq(); $query->flags(); $query->headerText(array('peek' => true)); try { $fetch_ret = $imap->fetch($mbox, $query, array('changedsince' => $folder->modseq())); } catch (Horde_Imap_Client_Exception $e) { $this->_logger->err($e->getMessage()); throw new Horde_ActiveSync_Exception($e); } // Prepare the changes and flags array, ensuring no changes after // $modseq sneak in yet (they will be caught on the next PING or // SYNC). $changes = array(); // Get custom flags to use as categories. $msgFlags = $this->_getMsgFlags(); foreach ($fetch_ret as $uid => $data) { if ($options['sincedate']) { $since = new Horde_Date($options['sincedate']); $headers = Horde_Mime_Headers::parseHeaders($data->getHeaderText()); try { $date = new Horde_Date($headers->getValue('Date')); if ($date->compareDate($since) <= -1) { // Ignore, it's out of the FILTERTYPE range. $this->_logger->info(sprintf('[%s] Ignoring UID %s since it is outside of the FILTERTYPE (%s)', $this->_procid, $uid, $headers->getValue('Date'))); continue; } } catch (Horde_Date_Exception $e) { } } if ($data->getModSeq() <= $modseq) { $changes[] = $uid; $flags[$uid] = array('read' => array_search(Horde_Imap_Client::FLAG_SEEN, $data->getFlags()) !== false ? 1 : 0); if ($options['protocolversion'] > Horde_ActiveSync::VERSION_TWOFIVE) { $flags[$uid]['flagged'] = array_search(Horde_Imap_Client::FLAG_FLAGGED, $data->getFlags()) !== false ? 1 : 0; } if ($options['protocolversion'] > Horde_ActiveSync::VERSION_TWELVEONE) { $categories[$uid] = array(); foreach ($data->getFlags() as $flag) { if (($key = array_search(strtolower($flag), array_map('strtolower', $msgFlags))) !== false) { $categories[$uid][] = $msgFlags[$key]; } } } } } $folder->setChanges($changes, $flags, $categories); try { $deleted = $imap->vanished($mbox, $folder->modseq(), array('ids' => new Horde_Imap_Client_Ids($folder->messages()))); } catch (Horde_Imap_Client_Excetion $e) { $this->_logger->err($e->getMessage()); throw new Horde_ActiveSync_Exception($e); } $folder->setRemoved($deleted->ids); if (!empty($options['softdelete']) && !empty($options['sincedate'])) { $this->_logger->info(sprintf('[%s] Polling for SOFTDELETE in %s before %d', $this->_procid, $folder->serverid(), $options['sincedate'])); $query = new Horde_Imap_Client_Search_Query(); $query->dateSearch(new Horde_Date($options['sincedate']), Horde_Imap_Client_Search_Query::DATE_BEFORE); $query->ids(new Horde_Imap_Client_Ids($folder->messages())); try { $search_ret = $imap->search($mbox, $query, array('results' => array(Horde_Imap_Client::SEARCH_RESULTS_MATCH))); } catch (Horde_Imap_Client_Exception $e) { $this->_logger->err($e->getMessage()); throw new Horde_ActiveSync_Exception($e); } if ($search_ret['count']) { $this->_logger->info(sprintf('[%s] Found %d messages to SOFTDELETE.', $this->_procid, count($search_ret['match']->ids))); $folder->setSoftDeleted($search_ret['match']->ids); } else { $this->_logger->info(sprintf('[%s] Found NO messages to SOFTDELETE.', $this->_procid)); } $folder->setSoftDeleteTimes($options['sincedate'], time()); } } elseif ($folder->uidnext() == 0) { $this->_logger->info(sprintf('[%s] INITIAL SYNC', $this->_procid)); $query = new Horde_Imap_Client_Search_Query(); if (!empty($options['sincedate'])) { $query->dateSearch(new Horde_Date($options['sincedate']), Horde_Imap_Client_Search_Query::DATE_SINCE); } $search_ret = $imap->search($mbox, $query, array('results' => array(Horde_Imap_Client::SEARCH_RESULTS_MATCH))); if ($modseq && $folder->modseq() > 0 && $search_ret['count']) { $folder->setChanges($search_ret['match']->ids, array()); } elseif (count($search_ret['match']->ids)) { $query = new Horde_Imap_Client_Fetch_Query(); $query->flags(); $fetch_ret = $imap->fetch($mbox, $query, array('ids' => $search_ret['match'])); foreach ($fetch_ret as $uid => $data) { $flags[$uid] = array('read' => array_search(Horde_Imap_Client::FLAG_SEEN, $data->getFlags()) !== false ? 1 : 0); if ($options['protocolversion'] > Horde_ActiveSync::VERSION_TWOFIVE) { $flags[$uid]['flagged'] = array_search(Horde_Imap_Client::FLAG_FLAGGED, $data->getFlags()) !== false ? 1 : 0; } } $folder->setChanges($search_ret['match']->ids, $flags); } } elseif ($modseq == 0) { $this->_logger->info(sprintf('[%s] NO CONDSTORE or per mailbox MODSEQ. minuid: %s, total_messages: %s', $this->_procid, $folder->minuid(), $status['messages'])); $folder->checkValidity($status); $query = new Horde_Imap_Client_Search_Query(); if (!empty($options['sincedate'])) { $query->dateSearch(new Horde_Date($options['sincedate']), Horde_Imap_Client_Search_Query::DATE_SINCE); } try { $search_ret = $imap->search($mbox, $query, array('results' => array(Horde_Imap_Client::SEARCH_RESULTS_MATCH))); } catch (Horde_Imap_Client_Exception $e) { $this->_logger->err($e->getMessage()); throw new Horde_ActiveSync_Exception($e); } if (count($search_ret['match']->ids)) { // Update flags. $query = new Horde_Imap_Client_Fetch_Query(); $query->flags(); try { $fetch_ret = $imap->fetch($mbox, $query, array('ids' => $search_ret['match'])); } catch (Horde_Imap_Client_Exception $e) { $this->_logger->err($e->getMessage()); throw new Horde_ActiveSync_Exception($e); } foreach ($fetch_ret as $uid => $data) { $flags[$uid] = array('read' => array_search(Horde_Imap_Client::FLAG_SEEN, $data->getFlags()) !== false ? 1 : 0); if ($options['protocolversion'] > Horde_ActiveSync::VERSION_TWOFIVE) { $flags[$uid]['flagged'] = array_search(Horde_Imap_Client::FLAG_FLAGGED, $data->getFlags()) !== false ? 1 : 0; } } $folder->setChanges($search_ret['match']->ids, $flags); } $folder->setRemoved($imap->vanished($mbox, null, array('ids' => new Horde_Imap_Client_Ids($folder->messages())))->ids); } elseif ($modseq > 0 && $folder->modseq() == 0) { throw new Horde_ActiveSync_Exception_StaleState('Transition to MODSEQ enabled server'); } $folder->setStatus($status); return $folder; }
/** * Adds an event to all the days it covers. * * @param array $result The current result list. * @param Kronolith_Event $event An event object. * @param Horde_Date $eventStart The event's start of the actual * recurrence. * @param Horde_Date $eventEnd The event's end of the actual * recurrence. * @param boolean $json Store the results of the events' * toJson() method? * @param Horde_Date $originalStart The actual starting time of a single * event spanning multiple days. * @param Horde_Date $originalEnd The actual ending time of a single * event spanning multiple days. */ public static function addCoverDates(&$results, $event, $eventStart, $eventEnd, $json, $originalStart = null, $originalEnd = null, Horde_Date $endDate = null) { $loopDate = new Horde_Date(array('month' => $eventStart->month, 'mday' => $eventStart->mday, 'year' => $eventStart->year)); $allDay = $event->isAllDay(); while ($loopDate->compareDateTime($eventEnd) <= 0 && $loopDate->compareDateTime($endDate) <= 0) { if (!$allDay || $loopDate->compareDateTime($eventEnd) != 0) { $addEvent = clone $event; if ($originalStart) { $addEvent->originalStart = $originalStart; } if ($originalEnd) { $addEvent->originalEnd = $originalEnd; } /* If this is the start day, set the start time to * the real start time, otherwise set it to * 00:00 */ if ($loopDate->compareDate($eventStart) != 0) { $addEvent->start = clone $loopDate; $addEvent->start->hour = $addEvent->start->min = $addEvent->start->sec = 0; $addEvent->first = false; } else { $addEvent->start = $eventStart; } /* If this is the end day, set the end time to the * real event end, otherwise set it to 23:59. */ if ($loopDate->compareDate($eventEnd) != 0) { $addEvent->end = clone $loopDate; $addEvent->end->hour = 23; $addEvent->end->min = $addEvent->end->sec = 59; $addEvent->last = false; } else { $addEvent->end = $eventEnd; } if ($addEvent->recurs() && $addEvent->recurrence->hasCompletion($loopDate->year, $loopDate->month, $loopDate->mday)) { $addEvent->status = Kronolith::STATUS_CANCELLED; } $results[$loopDate->dateString()][$addEvent->id] = $json ? $addEvent->toJson(array('all_day' => $allDay)) : $addEvent; } $loopDate->mday++; } }