function date_all_day_field in Date 7.2
Same name and namespace in other branches
- 8 date_all_day/date_all_day.module \date_all_day_field()
- 7.3 date_all_day/date_all_day.module \date_all_day_field()
Determine if a Start/End date combination qualify as 'All day'.
Parameters
array $field: The field definition for this date field.
array $instance: The field instance for this date field.
object $date1: A date/time object for the 'Start' date.
object $date2: A date/time object for the 'End' date.
Return value
bool TRUE or FALSE.
3 calls to date_all_day_field()
- date_all_day_date_formatter_dates_alter in date_all_day/
date_all_day.module - Implements hook_date_formatter_dates_alter().
- hook_date_formatter_dates_alter in ./
date.api.php - Alter the dates array created by date_formatter_process().
- theme_date_all_day in date_all_day/
date_all_day.module - Adjust start/end date format to account for 'all day' .
File
- date_all_day/
date_all_day.module, line 164 - Adds All Day functionality to the Date field.
Code
function date_all_day_field(array $field, array $instance, $date1, $date2 = NULL) {
if (empty($date1) || !is_object($date1)) {
return FALSE;
}
elseif (!date_has_time($field['settings']['granularity'])) {
return FALSE;
}
elseif (empty($instance['widget']['settings']['display_all_day'])) {
return FALSE;
}
if (empty($date2)) {
$date2 = $date1;
}
// Several scenarios result in the two date values being the same, e.g.
// date_formatter_process().
if ($date1 == $date2) {
// Clone the date object so that changes made to the object won't affect
// both variables.
$date1 = clone $date2;
// Set the time to midnight so that the two variables can be properly
// compared later in date_is_all_day().
$date1
->setTime(0, 0, 0);
}
// Use central logic for determining the granularity.
$granularity = date_granularity_precision($field['settings']['granularity']);
// The increment is 1 by default, but it can be overridden.
$increment = 1;
if (isset($instance['widget']['settings']['increment'])) {
$increment = $instance['widget']['settings']['increment'];
}
return date_is_all_day(date_format($date1, DATE_FORMAT_DATETIME), date_format($date2, DATE_FORMAT_DATETIME), $granularity, $increment);
}