function event_date_later in Event 5.2
Return a date $duration days or months after $date
Parameters
$date The date:
$duration The number of days, months, or seconds:
$type Optional, either "days", "months", "seconds", default "days":
Return value
The later date as a date array.
21 calls to event_date_later()
- event_calendar_data in ./
event.module - Returns an array of nodes that occur on a given date. Handles content type and taxonomy filters.
- event_calendar_ical in ./
event.module - Creates an ical feed of events.
- event_calendar_list in ./
event.module - Creates a themed list of events.
- event_calendar_month in ./
event.module - Displays a monthly event calendar.
- event_calendar_rss in ./
event.module - Creates an rss feed of events.
File
- ./
event.module, line 2999
Code
function event_date_later($date, $duration, $type = 'days') {
switch ($type) {
case 'days':
$end = explode('-', gmdate('Y-m-d', gmmktime(12, 0, 0, (int) $date['month'], (int) $date['day'] + $duration, (int) $date['year'])));
break;
case 'months':
$end = explode('-', gmdate('Y-m-d', gmmktime(12, 0, 0, (int) $date['month'] + $duration, (int) $date['day'], (int) $date['year'])));
// We need to validate that the resulting date will be in the
// $duration next month. Otherwise the 31st of February will be
// the 2nd of March.
// Check the number of months that we advanced and try again
// with a lesser day if it fails.
static $iteration;
if ($date['day'] > 28 && $iteration < 5 && abs(abs($date['year'] - $end[0]) * 12 - abs($date['month'] - $end[1]) != abs($duration))) {
$date['day']--;
$iteration++;
return event_date_later($date, $duration, 'months');
}
break;
case 'seconds':
$end = explode('-', gmdate('H-i-s-Y-m-d', gmmktime((int) $date['hour'], (int) $date['minute'], (int) $date['second'] + $duration, (int) $date['month'], (int) $date['day'], (int) $date['year'])));
break;
}
$end_date = array();
switch ($type) {
case 'days':
case 'months':
$end_date['year'] = $end['0'];
$end_date['month'] = $end['1'];
$end_date['day'] = $end['2'];
$end_date['hour'] = $date['hour'];
$end_date['minute'] = $date['minute'];
$end_date['second'] = $date['second'];
break;
case 'seconds':
$end_date['hour'] = $end['0'];
$end_date['minute'] = $end['1'];
$end_date['second'] = $end['2'];
$end_date['year'] = $end['3'];
$end_date['month'] = $end['4'];
$end_date['day'] = $end['5'];
break;
}
return $end_date;
}