function date_unset_granularity in Date 5
Unset undesired date part values.
3 calls to date_unset_granularity()
- date_copy_convert_events in ./
date_copy.module - date_field in ./
date.module - Implementation of hook_field().
- date_views_date_range in ./
date_views.inc
File
- ./
date.inc, line 1834 - Date/time API functions
Code
function date_unset_granularity($item, $granularity, $type) {
if (!($nongranularity = date_nongranularity_array($granularity))) {
return $item;
}
else {
if ($type == DATE_ISO) {
$date = date_iso2array($item);
}
else {
$date = date_unix2array($item);
}
foreach ($nongranularity as $level) {
switch ($level) {
case 'S':
$date['seconds'] = 0;
break;
case 'N':
$date['minutes'] = 0;
break;
case 'H':
$date['hours'] = 0;
break;
case 'M':
$date['mon'] = $type == DATE_UNIX ? 1 : 0;
break;
case 'D':
$date['mday'] = $type == DATE_UNIX ? 1 : 0;
break;
}
}
if ($type == DATE_ISO) {
return date_array2iso($date);
}
else {
return date_array2unix($date);
}
}
}