]> wagnertech.de Git - timetracker.git/blobdiff - WEB-INF/lib/common.lib.php
Refactored time_to_decimal for clarity.
[timetracker.git] / WEB-INF / lib / common.lib.php
index d98e8889298ca10d37dbe70a86051a4ca3d045d4..167b95b25be07acae2f1fbf763e09647f8bcbe87 100644 (file)
                }
        }
 
-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)