Skip to content

Instantly share code, notes, and snippets.

@tamboer
Last active December 15, 2015 12:49
Show Gist options
  • Select an option

  • Save tamboer/5263307 to your computer and use it in GitHub Desktop.

Select an option

Save tamboer/5263307 to your computer and use it in GitHub Desktop.
Zend_View_Helper_FormatToHourMinutes
<?php
class Zend_View_Helper_FormatToHourMinutes extends Zend_View_Helper_Abstract {
function formatToHourMinutes($decTime) {
if(!is_numeric($decTime))return $decTime;
$hour = floor($decTime);
$min = round(60 * ($decTime - $hour));
if($min !== 60) $time = sprintf('%02d:%02d', $hour, $min);
if($min == 60) $time = sprintf('%02d:%02d', $hour +1, '00');//to counter rounding of .9999999 to 60 minutes
//$time = sprintf('%02d:%02d', $hour, $min);
if ($time == '00:00')
$time = '';
return $time;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment