]> 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 3644c0587471ac433005eb93b83010c60785490a..167b95b25be07acae2f1fbf763e09647f8bcbe87 100644 (file)
                }
        }
 
-function time_to_decimal($a) {
-  $tmp = explode(":", $a);
-  if($tmp[1]{0}=="0") $tmp[1] = $tmp[1]{1};
+// 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;
+  $parts = explode(':', $val); // parts[0] is hours, parts[1] is minutes.
+
+  $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.
 
-  $m = round($tmp[1]*100/60);
+  $decimalTime = $parts[0].$user->decimal_mark.$minutePercent; // Construct decimal representation of time value.
 
-  if($m<10) $m = "0".$m;
-  $time = $tmp[0].".".$m;
-  return $time;
+  return $decimalTime;
 }
 
 function sec_to_time_fmt_hm($sec)
@@ -340,10 +342,3 @@ function ttAccessCheck($required_rights)
     
   return true;
 }
-
-// ttPluginEnabled is used to check whether a plugin is enabled for user.
-function ttPluginEnabled($plugin)
-{
-  global $user;
-  return in_array($plugin, explode(',', $user->plugins));
-}