A bit of refactoring.
[timetracker.git] / WEB-INF / lib / ttTimeHelper.class.php
index 3cef8b4..0d5863e 100644 (file)
@@ -173,7 +173,7 @@ class ttTimeHelper {
   // minutesToDuration converts an integer number of minutes into duration string.
   // Formats returned HH:MM, HHH:MM, HH, or HHH.
   static function minutesToDuration($minutes, $abbreviate = false) {
-    $sign = $minutes > 0 ? '' : '-';
+    $sign = $minutes >= 0 ? '' : '-';
     $minutes = abs($minutes);
 
     $hours = (string) (int)($minutes / 60);
@@ -188,8 +188,11 @@ class ttTimeHelper {
 
   // toMinutes - converts a time string in format 00:00 to a number of minutes.
   static function toMinutes($value) {
+    $signMultiplier = ttStartsWith($value, '-') ? -1 : 1;
+    if ($signMultiplier == -1) $duration = ltrim($duration, '-');
+
     $time_a = explode(':', $value);
-    return (int)@$time_a[1] + ((int)@$time_a[0]) * 60;
+    return $signMultiplier * ((int)@$time_a[1] + ((int)@$time_a[0]) * 60);
   }
 
   // toAbsDuration - converts a number of minutes to format 0:00
@@ -804,11 +807,12 @@ class ttTimeHelper {
   }
 
   // getRecords - returns time records for a user for a given date.
-  static function getRecords($user_id, $date) {
+  static function getRecords($date) {
     // TODO: merge getRecords and getRecordsWithFiles into one function.
     global $user;
     $mdb2 = getConnection();
 
+    $user_id = $user->getUser();
     $group_id = $user->getGroup();
     $org_id = $user->org_id;
 
@@ -866,10 +870,11 @@ class ttTimeHelper {
   // getRecordsWithFiles - returns time records for a user for a given date
   // with information whether they have attached files (has_files property).
   // A separate fiunction from getRecords because sql here is more complex.
-  static function getRecordsWithFiles($user_id, $date) {
+  static function getRecordsWithFiles($date) {
     global $user;
     $mdb2 = getConnection();
 
+    $user_id = $user->getUser();
     $group_id = $user->getGroup();
     $org_id = $user->org_id;