function timefield_time_to_duration in Timefield 7
Same name and namespace in other branches
- 1.0.x timefield.module \timefield_time_to_duration()
Helper function to return duration value from 2 values, in specified format.
Parameters
integer $value: First time value
integer $value2: Second time value
string $format: Out format options. Possible options are: -hours -minutes -seconds -time
@return mixed Integer or string depending on $format passed
1 call to timefield_time_to_duration()
- template_preprocess_timefield in ./
timefield.module - Preprocess function for the timefield.
File
- ./
timefield.module, line 1080 - Defines a Field API field for time
Code
function timefield_time_to_duration($value, $value2, $format) {
if ($value2 < $value) {
$value2 += 86400;
}
$duration = $value2 - $value;
switch ($format) {
case 'hours':
return round($duration / 60 / 60, 2);
break;
case 'minutes':
return round($duration / 60, 2);
break;
case 'seconds':
return $duration;
break;
case 'time':
return date('g:i', mktime(NULL, NULL, $duration));
break;
}
return 0;
}