From 809672af61a5feba4c8daa8c2f4b62e64177fc2b Mon Sep 17 00:00:00 2001 From: Nik Okuntseff Date: Wed, 6 Apr 2016 18:16:48 +0000 Subject: [PATCH] Refactored time_to_decimal for clarity. --- WEB-INF/lib/common.lib.php | 15 ++++++++------- WEB-INF/templates/footer.tpl | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/WEB-INF/lib/common.lib.php b/WEB-INF/lib/common.lib.php index d98e8889..167b95b2 100644 --- a/WEB-INF/lib/common.lib.php +++ b/WEB-INF/lib/common.lib.php @@ -143,16 +143,17 @@ } } -function time_to_decimal($a) { +// time_to_decimal converts a time string such as 1:15 to its decimal representation such as 1.25 or 1,25. +function time_to_decimal($val) { global $user; - $tmp = explode(":", $a); - if($tmp[1]{0}=="0") $tmp[1] = $tmp[1]{1}; + $parts = explode(':', $val); // parts[0] is hours, parts[1] is minutes. - $m = round($tmp[1]*100/60); + $minutePercent = round($parts[1]*100/60); // Integer value (0-98) of percent of minutes portion in the hour. + if($minutePercent < 10) $minutePercent = '0'.$minutePercent; // Pad small values with a 0 to always have 2 digits. - if($m<10) $m = "0".$m; - $time = $tmp[0].$user->decimal_mark.$m; - return $time; + $decimalTime = $parts[0].$user->decimal_mark.$minutePercent; // Construct decimal representation of time value. + + return $decimalTime; } function sec_to_time_fmt_hm($sec) diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index f15d95d6..6921dfc8 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.9.25.3496 | Copyright © Anuko | +  Anuko Time Tracker 1.9.25.3497 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} -- 2.20.1