本文整理汇总了PHP中Date_Calc::dateDiff方法的典型用法代码示例。如果您正苦于以下问题:PHP Date_Calc::dateDiff方法的具体用法?PHP Date_Calc::dateDiff怎么用?PHP Date_Calc::dateDiff使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Date_Calc
的用法示例。
在下文中一共展示了Date_Calc::dateDiff方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getAgo
public static function getAgo($timestamp)
{
if ($timestamp === null) {
return '';
}
$diffdays = Date_Calc::dateDiff(date('j', $timestamp), date('n', $timestamp), date('Y', $timestamp), date('j'), date('n'), date('Y'));
/* An error occured. */
if ($diffdays == -1) {
return;
}
$ago = $diffdays * Date_Calc::compareDates(date('j', $timestamp), date('n', $timestamp), date('Y', $timestamp), date('j'), date('n'), date('Y'));
if ($ago < -1) {
return sprintf(Horde_Model_Translation::t(" (%s days ago)"), $diffdays);
} elseif ($ago == -1) {
return Horde_Model_Translation::t(" (yesterday)");
} elseif ($ago == 0) {
return Horde_Model_Translation::t(" (today)");
} elseif ($ago == 1) {
return Horde_Model_Translation::t(" (tomorrow)");
} else {
return sprintf(Horde_Model_Translation::t(" (in %s days)"), $diffdays);
}
}
示例2: __construct
/**
* Constructor.
*
* @param object $event Event object
*/
public function __construct($event)
{
global $_EV_CONF;
$this->event = $event;
// Initialize array of events to be loaded
$this->events = array();
$this->freq = isset($event->rec_data['freq']) ? (int) $event->rec_data['freq'] : 1;
if ($this->freq < 1) {
$this->freq = 1;
}
$this->skip = isset($event->rec_data['skip']) ? (int) $event->rec_data['skip'] : 0;
$this->dt_start = $this->event->date_start1 != '' ? $this->event->date_start1 : $_EV_CONF['_today'];
$this->dt_end = $this->event->date_end1 > $this->event->date_start1 ? $this->event->date_end1 : $this->event->date_start1;
if ($this->dt_start != $this->dt_end) {
list($syear, $smonth, $sday) = explode('-', $this->dt_start);
list($eyear, $emonth, $eday) = explode('-', $this->dt_end);
// Need to get the number of days the event lasts
$this->duration = Date_Calc::dateDiff($eday, $emonth, $eyear, $sday, $smonth, $syear);
} else {
$this->duration = 0;
// single day event
}
}
示例3: Edit
//.........这里部分代码省略.........
$retval = '';
//$recinterval = '';
$recweekday = '';
$ownerusername = DB_getItem($_TABLES['users'], 'username', "uid='{$this->owner_id}'");
$retval .= COM_startBlock($LANG_EVLIST['event_editor']);
$summary = $this->Detail->summary;
$full_description = $this->Detail->full_description;
$location = $this->Detail->location;
if (($this->isAdmin || $_EV_CONF['allow_html'] == '1' && $_USER['uid'] > 1) && $A['postmode'] == 'html') {
$postmode = '2';
//html
} else {
$postmode = '1';
//plaintext
$summary = htmlspecialchars(COM_undoClickableLinks(COM_undoSpecialChars($this->Detail->summary)));
$full_description = htmlspecialchars(COM_undoClickableLinks(COM_undoSpecialChars($this->Detail->full_description)));
$location = htmlspecialchars(COM_undoClickableLinks(COM_undoSpecialChars($this->Detail->location)));
}
$starthour2 = '';
$startminute2 = '';
$endhour2 = '';
$endminute2 = '';
if ($this->date_end1 == '' || $this->date_end1 == '0000-00-00') {
$this->date_end1 = $this->date_start1;
}
if ($this->date_start1 != '' && $this->date_start1 != '0000-00-00') {
list($startmonth1, $startday1, $startyear1, $starthour1, $startminute1) = $this->DateParts($this->date_start1, $this->time_start1);
} else {
list($startmonth1, $startday1, $startyear1, $starthour1, $startminute1) = $this->DateParts(date('Y-m-d', time()), date('H:i:s', time()));
}
// The end date can't be before the start date
if ($this->date_end1 >= $this->date_start1) {
list($endmonth1, $endday1, $endyear1, $endhour1, $endminute1) = $this->DateParts($this->date_end1, $this->time_end1);
$days_interval = Date_Calc::dateDiff($endday1, $endmonth1, $endyear1, $startday1, $startmonth1, $startyear1);
} else {
$days_interval = 0;
$endmonth1 = $startmonth1;
$endday1 = $startday1;
$endyear1 = $startyear1;
$endhour1 = $starthour1;
$endminute1 = $startminute1;
}
if ($this->recurring != '1') {
$T->set_var(array('recurring_show' => ' style="display:none;"', 'format_opt' => '0'));
//for ($i = 1; $i <= 6; $i++) {
// $T->set_var('format' . $i . 'show', ' style="display:none;"');
//}
} else {
$option = empty($this->rec_data['type']) ? '0' : (int) $this->rec_data['type'];
$T->set_var(array('recurring_show' => '', 'recurring_checked' => EVCHECKED, 'format_opt' => $option));
}
if (isset($this->rec_data['stop']) && !empty($this->rec_data['stop'])) {
$T->set_var(array('stopdate' => $this->rec_data['stop'], 'd_stopdate' => EVLIST_formattedDate($this->rec_data['stop'])));
}
if (!empty($this->rec_data['skip'])) {
$T->set_var("skipnext{$this->rec_data['skip']}_checked", EVCHECKED);
}
if (!empty($this->rec_data['freq'])) {
$freq = (int) $this->rec_data['freq'];
if ($freq < 1) {
$freq = 1;
}
} else {
$freq = 1;
}
$T->set_var(array('freq_text' => $LANG_EVLIST['rec_periods'][$this->rec_data['type']] . '(s)', 'rec_freq' => $freq));
示例4: importMatching
function importMatching($importedTransaction, $accountId)
{
global $us;
global $badgerDb;
static $dateDelta = null;
static $amountDelta = null;
static $textSimilarity = null;
static $categories = null;
if (is_null($dateDelta)) {
try {
$dateDelta = $us->getProperty('matchingDateDelta');
} catch (BadgerException $ex) {
$dateDelta = 5;
}
try {
$amountDelta = $us->getProperty('matchingAmountDelta');
} catch (BadgerException $ex) {
$amountDelta = 0.1;
}
try {
$textSimilarity = $us->getProperty('matchingTextSimilarity');
} catch (BadgerException $ex) {
$textSimilarity = 0.25;
}
$categoryManager = new CategoryManager($badgerDb);
while ($currentCategory = $categoryManager->getNextCategory()) {
$categories[$currentCategory->getId()] = preg_split('/[\\n]+/', $currentCategory->getKeywords(), -1, PREG_SPLIT_NO_EMPTY);
}
}
if (!$importedTransaction['valutaDate']) {
return $importedTransaction;
}
$minDate = new Date($importedTransaction['valutaDate']);
$minDate->subtractSeconds($dateDelta * 24 * 60 * 60);
$maxDate = new Date($importedTransaction['valutaDate']);
$maxDate->addSeconds($dateDelta * 24 * 60 * 60);
if (!$importedTransaction['amount']) {
return $importedTransaction;
}
$minAmount = new Amount($importedTransaction['amount']);
$minAmount->mul(1 - $amountDelta);
$maxAmount = new Amount($importedTransaction['amount']);
$maxAmount->mul(1 + $amountDelta);
$accountManager = new AccountManager($badgerDb);
$account = $accountManager->getAccountById($accountId);
$account->setFilter(array(array('key' => 'valutaDate', 'op' => 'ge', 'val' => $minDate), array('key' => 'valutaDate', 'op' => 'le', 'val' => $maxDate), array('key' => 'amount', 'op' => 'ge', 'val' => $minAmount), array('key' => 'amount', 'op' => 'le', 'val' => $maxAmount)));
$similarTransactions = array();
while ($currentTransaction = $account->getNextTransaction()) {
$titleSimilarity = getSimilarity($importedTransaction['title'], $currentTransaction->getTitle(), $textSimilarity);
$descriptionSimilarity = getSimilarity($importedTransaction['description'], $currentTransaction->getDescription(), $textSimilarity);
$transactionPartnerSimilarity = getSimilarity($importedTransaction['transactionPartner'], $currentTransaction->getTransactionPartner(), $textSimilarity);
$currDate = $currentTransaction->getValutaDate();
$impDate = $importedTransaction['valutaDate'];
$dateSimilarity = 1 - abs(Date_Calc::dateDiff($currDate->getDay(), $currDate->getMonth(), $currDate->getYear(), $impDate->getDay(), $impDate->getMonth(), $impDate->getYear())) / $dateDelta;
$cmpAmount = new Amount($currentTransaction->getAmount());
$impAmount = new Amount($importedTransaction['amount']);
$cmpAmount->sub($impAmount);
$cmpAmount->abs();
$impAmount->mul($amountDelta);
$impAmount->abs();
$amountSimilarity = 1 - $cmpAmount->div($impAmount)->get();
$currentTextSimilarity = ($titleSimilarity + $descriptionSimilarity + $transactionPartnerSimilarity) / 3;
// if ($currentTextSimilarity >= $textSimilarity) {
$overallSimilarity = ($titleSimilarity + $descriptionSimilarity + $transactionPartnerSimilarity + $dateSimilarity + $amountSimilarity) / 5;
//$similarTransactions["$overallSimilarity t:$titleSimilarity d:$descriptionSimilarity tp:$transactionPartnerSimilarity vd:$dateSimilarity a:$amountSimilarity"] = $currentTransaction;
$similarTransactions[$overallSimilarity] = $currentTransaction;
// }
}
krsort($similarTransactions);
if (count($similarTransactions)) {
$importedTransaction['similarTransactions'] = $similarTransactions;
return $importedTransaction;
}
if ($importedTransaction['categoryId']) {
return $importedTransaction;
}
$transactionStrings = array($importedTransaction['title'], $importedTransaction['description'], $importedTransaction['transactionPartner']);
foreach ($transactionStrings as $currentTransactionString) {
foreach ($categories as $currentCategoryId => $keywords) {
foreach ($keywords as $keyword) {
if (stripos($currentTransactionString, trim($keyword)) !== false) {
$importedTransaction['categoryId'] = $currentCategoryId;
break 3;
}
//if keyword found
}
//foreach keywords
}
//foreach categories
}
//foreach transactionStrings
return $importedTransaction;
}
示例5: computeSubscriptionDays
private function computeSubscriptionDays($p_publication, $p_subscriptionTime) {
$startDate = new Date();
if ($p_publication->getTimeUnit() == 'D') {
return $p_subscriptionTime;
} elseif ($p_publication->getTimeUnit() == 'W') {
return 7 * $p_subscriptionTime;
} elseif ($p_publication->getTimeUnit() == 'M') {
$endDate = new Date();
$months = $p_subscriptionTime + $endDate->getMonth();
$years = (int)($months / 12);
$months = $months % 12;
$endDate->setYear($endDate->getYear() + $years);
$endDate->setMonth($months);
} elseif ($p_publication->getTimeUnit() == 'Y') {
$endDate = new Date();
$endDate->setYear($endDate->getYear() + $p_subscriptionTime);
}
$dateCalc = new Date_Calc();
return $dateCalc->dateDiff($endDate->getDay(), $endDate->getMonth(),
$endDate->getYear(), $startDate->getDay(), $startDate->getMonth(), $startDate->getYear());
}
示例6: compare
compare('20050126', Date_Calc::NWeekdayOfMonth('last', 3, 1, 2005), 'NWeekdayOfMonth l31');
compare('20050125', Date_Calc::NWeekdayOfMonth('last', 2, 1, 2005), 'NWeekdayOfMonth l21');
compare('20050331', Date_Calc::NWeekdayOfMonth('last', 4, 3, 2005), 'NWeekdayOfMonth l43');
compare('20050330', Date_Calc::NWeekdayOfMonth('last', 3, 3, 2005), 'NWeekdayOfMonth l33');
compare('20050329', Date_Calc::NWeekdayOfMonth('last', 2, 3, 2005), 'NWeekdayOfMonth l23');
compare('20050328', Date_Calc::NWeekdayOfMonth('last', 1, 3, 2005), 'NWeekdayOfMonth l13');
compare('20050327', Date_Calc::NWeekdayOfMonth('last', 0, 3, 2005), 'NWeekdayOfMonth l03');
compare('20050326', Date_Calc::NWeekdayOfMonth('last', 6, 3, 2005), 'NWeekdayOfMonth l63');
compare('20050325', Date_Calc::NWeekdayOfMonth('last', 5, 3, 2005), 'NWeekdayOfMonth l53');
compare(false, Date_Calc::isValidDate(29, 2, 1900), 'isValidDate 1');
compare(true, Date_Calc::isValidDate(29, 2, 2000), 'isValidDate 2');
compare(true, Date_Calc::isValidDate('29', '02', '2000'), 'isValidDate 2 str');
compare(false, Date_Calc::isLeapYear(1900), 'isLeapYear 1');
compare(true, Date_Calc::isLeapYear(1996), 'isLeapYear 2');
compare(true, Date_Calc::isLeapYear(2000), 'isLeapYear 3');
compare(false, Date_Calc::isLeapYear(2001), 'isLeapYear 4');
compare(false, Date_Calc::isLeapYear('2001'), 'isLeapYear 4 str');
compare(false, Date_Calc::isFutureDate('22', '11', '2000'), 'isFutureDate 1 str');
compare(false, Date_Calc::isFutureDate(22, 11, 2000), 'isFutureDate 1');
compare(true, Date_Calc::isFutureDate(22, 11, date('Y') + 1), 'isFutureDate 2');
compare(false, Date_Calc::isPastDate(22, 11, date('Y') + 1), 'isPastDate 1');
compare(true, Date_Calc::isPastDate(22, 11, 2000), 'isPastDate 2');
compare(true, Date_Calc::isPastDate('22', '11', '2000'), 'isPastDate 2 str');
compare(10, Date_Calc::dateDiff(22, 11, 2000, 12, 11, 2000), 'dateDiff 1');
compare(10, Date_Calc::dateDiff(12, 11, 2000, 22, 11, 2000), 'dateDiff 2');
compare(61, Date_Calc::dateDiff(22, 11, 2000, 22, 1, 2001), 'dateDiff 3');
compare(61, Date_Calc::dateDiff('22', '11', '2000', '22', '01', '2001'), 'dateDiff 3 str');
compare(-1, Date_Calc::compareDates(12, 11, 2000, 22, 11, 2000), 'compareDates 1');
compare(0, Date_Calc::compareDates(22, 11, 2000, 22, 11, 2000), 'compareDates 2');
compare(1, Date_Calc::compareDates(22, 11, 2000, 12, 11, 2000), 'compareDates 3');
compare(1, Date_Calc::compareDates('22', '11', '2000', '12', '11', '2000'), 'compareDates 3 str');
示例7: getEventsForPeriod
/**
* Utility function to return an array of events with a period
* @param Date Start date of the period
* @param Date End date of the period
* @return array A list of events
*/
function getEventsForPeriod($start_date, $end_date, $filter = 'all', $user_id = null, $project_id = 0)
{
global $AppUI;
// the event times are stored as unix time stamps, just to be different
// convert to default db time stamp
$db_start = $start_date->format(FMT_DATETIME_MYSQL);
$db_end = $end_date->format(FMT_DATETIME_MYSQL);
if (!isset($user_id)) {
$user_id = $AppUI->user_id;
}
$project =& new CProject();
if ($project_id) {
$p =& $AppUI->acl();
if ($p->checkModuleItem('projects', 'view', $project_id, $user_id)) {
$allowedProjects = array('p.project_id = ' . $project_id);
} else {
$allowedProjects = array('1=0');
}
} else {
$allowedProjects = $project->getAllowedSQL($user_id, 'event_project');
}
//do similiar actions for recurring and non-recurring events
$queries = array('q' => 'q', 'r' => 'r');
foreach ($queries as $query_set) {
${$query_set} = new DBQuery();
${$query_set}->addTable('events', 'e');
${$query_set}->addQuery('e.*');
${$query_set}->addOrder('e.event_start_date, e.event_end_date ASC');
${$query_set}->addJoin('projects', 'p', 'p.project_id = e.event_project');
if ($AppUI->getState('CalIdxCompany')) {
${$query_set}->addWhere('project_company = ' . $AppUI->getState('CalIdxCompany'));
}
if (count($allowedProjects)) {
${$query_set}->addWhere('((' . implode(' AND ', $allowedProjects) . ') ' . ($AppUI->getState('CalIdxCompany') ? '' : $project_id ? '' : ' OR event_project = 0 ') . ')');
}
switch ($filter) {
case 'my':
${$query_set}->addJoin('user_events', 'ue', 'ue.event_id = e.event_id AND ue.user_id =' . $user_id);
${$query_set}->addWhere('(ue.user_id = ' . $user_id . ') AND (event_private=0 OR event_owner=' . $user_id . ')');
break;
case 'own':
${$query_set}->addWhere('event_owner =' . $user_id);
break;
case 'all':
${$query_set}->addWhere('(event_private=0 OR event_owner=' . $user_id . ')');
break;
}
if ($query_set == 'q') {
// assemble query for non-recursive events
${$query_set}->addWhere('(event_recurs <= 0)');
// following line is only good for *non-recursive* events
${$query_set}->addWhere("(event_start_date <= '{$db_end}' AND event_end_date >= '{$db_start}' " . "OR event_start_date BETWEEN '{$db_start}' AND '{$db_end}')");
$eventList = ${$query_set}->loadList();
} else {
if ($query_set == 'r') {
// assemble query for recursive events
${$query_set}->addWhere('(event_recurs > 0)');
$eventListRec = ${$query_set}->loadList();
}
}
}
//Calculate the Length of Period (Daily, Weekly, Monthly View)
setlocale(LC_TIME, 'en_AU');
$periodLength = Date_Calc::dateDiff($start_date->getDay(), $start_date->getMonth(), $start_date->getYear(), $end_date->getDay(), $end_date->getMonth(), $end_date->getYear());
setlocale(LC_ALL, $AppUI->user_lang);
// AJD: Should this be going off the end of the array? I don't think so.
// If it should then a comment to that effect would be nice.
// for ($i=0; $i < sizeof($eventListRec)+1; $i++) {
for ($i = 0, $sz = sizeof($eventListRec); $i < $sz; $i++) {
//note from merlinyoda: j=0 is the original event according to getRecurrentEventforPeriod
// So, since the event is *recurring* x times, the loop condition should be j <= x, not j < x.
// This way the original and all recurrances are covered.
//for ($j=0; $j < intval($eventListRec[$i]['event_times_recuring']); $j++) {
for ($j = 0, $end = intval($eventListRec[$i]['event_times_recuring']); $j < $end; $j++) {
if ($periodLength == 1) {
// Daily View: show all
$recEventDate = CEvent::getRecurrentEventforPeriod($start_date, $end_date, $eventListRec[$i]['event_start_date'], $eventListRec[$i]['event_end_date'], $eventListRec[$i]['event_recurs'], $eventListRec[$i]['event_times_recuring'], $j);
} elseif ($periodLength > 1 && $eventListRec[$i]['event_recurs'] == 1 && $j == 0) {
// Weekly or Monthly View and Hourly Recurrent Events: show one time and add string 'hourly'
$recEventDate = CEvent::getRecurrentEventforPeriod($start_date, $end_date, $eventListRec[$i]['event_start_date'], $eventListRec[$i]['event_end_date'], $eventListRec[$i]['event_recurs'], $eventListRec[$i]['event_times_recuring'], $j);
$eventListRec[$i]['event_title'] = $eventListRec[$i]['event_title'] . ' (' . $AppUI->_('Hourly') . ')';
} elseif ($periodLength > 1 && $eventListRec[$i]['event_recurs'] > 1) {
//Weekly and Monthly View and higher recurrence mode: show all events of recurrence > 1
$recEventDate = CEvent::getRecurrentEventforPeriod($start_date, $end_date, $eventListRec[$i]['event_start_date'], $eventListRec[$i]['event_end_date'], $eventListRec[$i]['event_recurs'], $eventListRec[$i]['event_times_recuring'], $j);
}
//add values to the eventsArray if check for recurrent event was positive
if (sizeof($recEventDate) > 0) {
$eList[0] = $eventListRec[$i];
$eList[0]['event_start_date'] = $recEventDate[0]->format(FMT_DATETIME_MYSQL);
$eList[0]['event_end_date'] = $recEventDate[1]->format(FMT_DATETIME_MYSQL);
$eventList = array_merge($eventList, $eList);
}
// clear array of positive recurrent events for the case that next loop recEventDate is empty in order to avoid double display
$recEventDate = array();
//.........这里部分代码省略.........
示例8: countDays
/**
* How many whole days are covered by the range?
*
* @return int The number of whole days covered by the range.
*/
function countDays()
{
$start = $this->getStartDate();
$end = $this->getEndDate();
$days = Date_Calc::dateDiff($start->getDay(), $start->getMonth(), $start->getYear(), $end->getDay(), $end->getMonth(), $end->getYear());
return $days;
}
示例9: listAlarms
/**
*
* @param Horde_Date $date The date to list alarms for
* @param boolean $fullevent Return the full event objects?
*
* @return array An array of event ids, or Kronolith_Event objects
* @throws Kronolith_Exception
*/
public function listAlarms($date, $fullevent = false)
{
$allevents = $this->listEvents($date, null, array('has_alarm' => true));
$events = array();
foreach ($allevents as $dayevents) {
foreach ($dayevents as $event) {
if (!$event->recurs()) {
$start = new Horde_Date($event->start);
$start->min -= $event->alarm;
if ($start->compareDateTime($date) <= 0 && $date->compareDateTime($event->end) <= -1) {
$events[] = $fullevent ? $event : $event->id;
}
} else {
// Need to start at the beginning of the day to catch the
// case where we might be within the event's timespan
// when we call this, hence nextRecurrence() would miss the
// current event.
$start = clone $date;
$start->min = 0;
$start->hour = 0;
$start->sec = 0;
if ($next = $event->recurrence->nextRecurrence($start)) {
if ($event->recurrence->hasException($next->year, $next->month, $next->mday)) {
continue;
}
$start = new Horde_Date($next);
$start->min -= $event->alarm;
$diff = Date_Calc::dateDiff($event->start->mday, $event->start->month, $event->start->year, $event->end->mday, $event->end->month, $event->end->year);
if ($diff == -1) {
$diff = 0;
}
$end = new Horde_Date(array('year' => $next->year, 'month' => $next->month, 'mday' => $next->mday + $diff, 'hour' => $event->end->hour, 'min' => $event->end->min, 'sec' => $event->end->sec));
if ($start->compareDateTime($date) <= 0 && $date->compareDateTime($end) <= -1) {
if ($fullevent) {
$event->start = $next;
$event->end = $end;
$events[] = $event;
} else {
$events[] = $event->id;
}
}
}
}
}
}
return $events;
}
示例10: _content
/**
*/
protected function _content()
{
global $page_output;
$page_output->addScriptFile('tooltips.js', 'horde');
$now = new Horde_Date($_SERVER['REQUEST_TIME']);
$today = date('j');
$current_month = '';
$startDate = new Horde_Date(array('year' => date('Y'), 'month' => date('n'), 'mday' => date('j')));
$endDate = new Horde_Date(array('year' => date('Y'), 'month' => date('n') + $this->_params['months'], 'mday' => date('j') - 1));
try {
if (isset($this->_params['calendar']) && $this->_params['calendar'] != '__all') {
$calendars = Kronolith::listCalendars();
if (!isset($calendars[$this->_params['calendar']])) {
return _("Calendar not found");
}
if (!$calendars[$this->_params['calendar']]->hasPermission(Horde_Perms::READ)) {
return _("Permission Denied");
}
list($type, $calendar) = explode('_', $this->_params['calendar'], 2);
$driver = Kronolith::getDriver($type, $calendar);
$all_events = $driver->listEvents($startDate, $endDate, array('show_recurrence' => true, 'has_alarm' => !empty($this->_params['alarms']), 'cover_dates' => false));
} else {
$all_events = Kronolith::listEvents($startDate, $endDate, $GLOBALS['calendar_manager']->get(Kronolith::DISPLAY_CALENDARS), array('has_alarm' => !empty($this->_params['alarms']), 'cover_dates' => false));
}
} catch (Exception $e) {
return '<em>' . $e->getMessage() . '</em>';
}
/* How many days do we need to check. */
$days = Date_Calc::dateDiff($startDate->mday, $startDate->month, $startDate->year, $endDate->mday, $endDate->month, $endDate->year);
/* Loop through the days. */
$totalevents = 0;
$html = '';
for ($i = 0; $i < $days; ++$i) {
$day = new Kronolith_Day($startDate->month, $today + $i);
$date_stamp = $day->dateString();
if (empty($all_events[$date_stamp])) {
continue;
}
if (!empty($this->_params['maxevents']) && $totalevents >= $this->_params['maxevents']) {
break;
}
/* Output month header. */
if ($current_month != $day->month) {
$html .= '<tr><td colspan="4" class="control"><strong>' . $day->strftime('%B') . '</strong></td></tr>';
}
$firstevent = true;
$tomorrow = $day->getTomorrow();
foreach ($all_events[$date_stamp] as $event) {
$isMultiDay = false;
if ($event->start->compareDate($day) < 0) {
$event->start = new Horde_Date($day);
}
if ($event->end->compareDate($tomorrow) >= 1) {
$isMultiDay = true;
}
if ($event->end->compareDate($now) < 0 && !$event->isAllDay() || !empty($this->_params['alarms']) && !$event->alarm) {
continue;
}
if ($firstevent || $isMultiDay) {
$html .= '<tr';
if ($current_month == $day->month) {
$html .= ' class="upcomingday"';
}
$html .= '><td class="text" valign="top" align="right"><strong>';
if ($day->isToday()) {
$html .= _("Today");
} elseif ($day->isTomorrow()) {
$html .= _("Tomorrow");
} else {
$html .= $day->mday;
}
if ($isMultiDay) {
$endDay = new Kronolith_Day($event->end->month, $event->end->mday);
$html .= ' - ';
if ($endDay->isTomorrow()) {
$html .= _("Tomorrow");
} else {
$html .= $event->end->mday;
}
}
$html .= '</strong> </td>';
$firstevent = $isMultiDay;
} else {
$html .= '<tr><td class="text"> </td>';
}
$html .= '<td class="text" nowrap="nowrap" valign="top">';
if ($event->start->compareDate($now) < 0 && $event->end->compareDate($now) > 0) {
$html .= '<strong>' . htmlspecialchars($event->getLocation()) . '</strong>';
} else {
$html .= htmlspecialchars($event->getLocation());
}
if ($event->start->compareDate($now) < 0 && $event->end->compareDate($now) > 0) {
$html .= '<strong>';
}
$html .= $event->getLink(null, true, null, true);
if ($event->start->compareDate($now) < 0 && $event->end->compareDate($now) > 0) {
$html .= '</strong>';
}
//.........这里部分代码省略.........
示例11: diff
public function diff($other = null)
{
$day2 = new Kronolith_Day();
return Date_Calc::dateDiff($this->mday, $this->month, $this->year, $day2->mday, $day2->month, $day2->year);
}
示例12: dateDiff
/**
* New method to get the difference in days the stored date
* @author Andrew Eddie <eddieajau@users.sourceforge.net>
*
* @param $when
* @return bool|int
*/
public function dateDiff($when)
{
if (!is_object($when)) {
return false;
}
$date_calc = new Date_Calc();
return $date_calc->dateDiff($this->getDay(), $this->getMonth(), $this->getYear(), $when->getDay(), $when->getMonth(), $when->getYear());
}
示例13: setFromDateDiff
/**
* Sets the span from the elapsed time between two dates
*
* The time span is unsigned, so the date's order is not important.
*
* @param object $date1 first Date
* @param object $date2 second Date
*
* @return bool true on success
* @access public
* @see Date_Span::set()
*/
function setFromDateDiff($date1, $date2)
{
if (!is_a($date1, 'date') or !is_a($date2, 'date')) {
return false;
}
// create a local copy of instance, in order avoid changes the object
// reference when its object has converted to UTC due PHP5 is always
// passed the object by reference.
$tdate1 = new Date($date1);
$tdate2 = new Date($date2);
// convert to UTC
$tdate1->toUTC();
$tdate2->toUTC();
if ($tdate1->after($tdate2)) {
list($tdate1, $tdate2) = array($tdate2, $tdate1);
}
$days = Date_Calc::dateDiff($tdate1->getDay(), $tdate1->getMonth(), $tdate1->getYear(), $tdate2->getDay(), $tdate2->getMonth(), $tdate2->getYear());
$hours = $tdate2->getHour() - $tdate1->getHour();
$mins = $tdate2->getMinute() - $tdate1->getMinute();
$secs = $tdate2->getSecond() - $tdate1->getSecond();
$this->setFromSeconds($days * 86400 + $hours * 3600 + $mins * 60 + $secs);
return true;
}
示例14: saveSummary
/**
* A method to update the summary table from the intermediate tables.
*
* @param PEAR::Date $oStartDate The start date/time to update from.
* @param PEAR::Date $oEndDate The end date/time to update to.
* @param array $aActions An array of data types to summarise. Contains
* two array, the first containing the data types,
* and the second containing the connection type
* values associated with those data types, if
* appropriate. For example:
* array(
* 'types' => array(
* 0 => 'request',
* 1 => 'impression',
* 2 => 'click'
* ),
* 'connections' => array(
* 1 => MAX_CONNECTION_AD_IMPRESSION,
* 2 => MAX_CONNECTION_AD_CLICK
* )
* )
* Note that the order of the items must match
* the order of the items in the database tables
* (e.g. in data_intermediate_ad and
* data_summary_ad_hourly for the above example).
* @param string $fromTable The name of the intermediate table to summarise
* from (e.g. 'data_intermediate_ad').
* @param string $toTable The name of the summary table to summarise to
* (e.g. 'data_summary_ad_hourly').
*/
function saveSummary($oStartDate, $oEndDate, $aActions, $fromTable, $toTable)
{
$aConf = $GLOBALS['_MAX']['CONF'];
// Check that there are types to summarise
if (empty($aActions['types']) || empty($aActions['connections'])) {
return;
}
// How many days does the start/end period span?
$days = Date_Calc::dateDiff($oStartDate->getDay(), $oStartDate->getMonth(), $oStartDate->getYear(), $oEndDate->getDay(), $oEndDate->getMonth(), $oEndDate->getYear());
if ($days == 0) {
// Save the data
$this->_saveSummary($oStartDate, $oEndDate, $aActions, $fromTable, $toTable);
} else {
// Save each day's data separately
for ($counter = 0; $counter <= $days; $counter++) {
if ($counter == 0) {
// This is the first day
$oInternalStartDate = new Date();
$oInternalStartDate->copy($oStartDate);
$oInternalEndDate = new Date($oStartDate->format('%Y-%m-%d') . ' 23:59:59');
} elseif ($counter == $days) {
// This is the last day
$oInternalStartDate = new Date($oEndDate->format('%Y-%m-%d') . ' 00:00:00');
$oInternalEndDate = new Date();
$oInternalEndDate->copy($oEndDate);
} else {
// This is a day in the middle
$oDayDate = new Date();
$oDayDate->copy($oStartDate);
$oDayDate->addSeconds(SECONDS_PER_DAY * $counter);
$oInternalStartDate = new Date($oDayDate->format('%Y-%m-%d') . ' 00:00:00');
$oInternalEndDate = new Date($oDayDate->format('%Y-%m-%d') . ' 23:59:59');
}
$this->_saveSummary($oInternalStartDate, $oInternalEndDate, $aActions, $fromTable, $toTable);
}
}
}
示例15: getEventsForPeriod
/**
* Utility function to return an array of events with a period
* @param Date Start date of the period
* @param Date End date of the period
* @return array A list of events
*/
function getEventsForPeriod($start_date, $end_date, $filter = 'all', $user_id = null, $project_id = 0)
{
global $AppUI;
// the event times are stored as unix time stamps, just to be different
// convert to default db time stamp
$db_start = $start_date->format(FMT_DATETIME_MYSQL);
$db_end = $end_date->format(FMT_DATETIME_MYSQL);
if (!isset($user_id)) {
$user_id = $AppUI->user_id;
}
$project = new CProject();
if ($project_id) {
$p =& $AppUI->acl();
if ($p->checkModuleItem('projects', 'view', $project_id, $user_id)) {
$allowedProjects = array('p.project_id = ' . $project_id);
} else {
$allowedProjects = array('1=0');
}
} else {
$allowedProjects = $project->getAllowedSQL($user_id, 'event_project');
}
//do similiar actions for recurring and non-recurring events
$queries = array('q' => 'q', 'r' => 'r');
foreach ($queries as $query_set) {
${$query_set} = new DBQuery();
${$query_set}->addTable('events', 'e');
${$query_set}->addQuery('DISTINCT e.*');
${$query_set}->addOrder('e.event_start_date, e.event_end_date ASC');
${$query_set}->addJoin('projects', 'p', 'p.project_id = e.event_project');
if ($AppUI->getState('CalIdxCompany')) {
${$query_set}->addWhere('p.project_company = ' . $AppUI->getState('CalIdxCompany'));
}
if (count($allowedProjects)) {
${$query_set}->addWhere('((' . implode(' AND ', $allowedProjects) . ') ' . ($AppUI->getState('CalIdxCompany') || $project_id ? '' : ' OR event_project = 0 ') . ')');
}
switch ($filter) {
case 'my':
${$query_set}->addJoin('user_events', 'ue', 'ue.event_id = e.event_id AND ue.user_id =' . $user_id);
${$query_set}->addWhere('(ue.user_id = ' . $user_id . ') AND (event_private=0 OR event_owner=' . $user_id . ')');
break;
case 'own':
${$query_set}->addWhere('e.event_owner =' . $user_id);
break;
case 'all':
${$query_set}->addWhere('(e.event_private=0 OR e.event_owner=' . $user_id . ')');
break;
}
if ($query_set == 'q') {
// assemble query for non-recursive events
// following line is only good for *non-recursive* events
${$query_set}->addWhere('(event_recurs <= 0)');
${$query_set}->addWhere("(event_start_date < '{$db_end}'" . " AND event_end_date > '{$db_start}')");
$eventList = ${$query_set}->loadList();
} else {
if ($query_set == 'r') {
// assemble query for recursive events
${$query_set}->addWhere('(event_recurs > 0)');
$eventListRec = ${$query_set}->loadList();
}
}
}
//Calculate the Length of Period (Daily, Weekly, Monthly View)
setlocale(LC_ALL, 'en_AU' . ($locale_char_set ? '.' . $locale_char_set : '.utf8'));
$periodLength = Date_Calc::dateDiff($end_date->getDay(), $end_date->getMonth(), $end_date->getYear(), $start_date->getDay(), $start_date->getMonth(), $start_date->getYear());
setlocale(LC_ALL, $AppUI->user_lang);
foreach ($eventListRec as $key => $ia) {
$end = intval($ia['event_times_recuring']);
for ($j = 0; $j < $end; $j++) {
$recEventDate = array();
if ($periodLength <= 1) {
// Daily View or clash check: show all
$recEventDate = CEvent::getRecurrentEventforPeriod($start_date, $end_date, $ia['event_start_date'], $ia['event_end_date'], $ia['event_recurs'], $ia['event_times_recuring'], $j);
} else {
if ($ia['event_recurs'] == 1 && $j == 0) {
// Weekly or Monthly View and Hourly Recurrent Events
//show one time and add string 'hourly'
$recEventDate = CEvent::getRecurrentEventforPeriod($start_date, $end_date, $ia['event_start_date'], $ia['event_end_date'], $ia['event_recurs'], $ia['event_times_recuring'], $j);
$eventListRec[$key]['event_title'] = $ia['event_title'] . ' (' . $AppUI->_('Hourly') . ')';
} else {
if ($ia['event_recurs'] > 1) {
//Weekly and Monthly View and higher recurrence mode
//show all events of recurrence > 1
$recEventDate = CEvent::getRecurrentEventforPeriod($start_date, $end_date, $ia['event_start_date'], $ia['event_end_date'], $ia['event_recurs'], $ia['event_times_recuring'], $j);
}
}
}
//add values to the eventsArray if check for recurrent event was positive
if (!empty($recEventDate)) {
$display_start = $recEventDate[0]->format(FMT_DATETIME_MYSQL);
$display_end = $recEventDate[1]->format(FMT_DATETIME_MYSQL);
$eventListRec[$key]['event_start_date'] = $display_start;
$eventListRec[$key]['event_end_date'] = $display_end;
$eventList = array_merge($eventList, array($eventListRec[$key]));
}
//.........这里部分代码省略.........