As suggested in PR#33, allowed entry of decimal values with a comma for teams with...
[timetracker.git] / WEB-INF / lib / ttTimeHelper.class.php
index e574dc8..13a2d83 100644 (file)
@@ -31,6 +31,24 @@ import('DateAndTime');
 // The ttTimeHelper is a class to help with time-related values.
 class ttTimeHelper {
 
+  // isWeekend determines if $date falls on weekend.
+  static function isWeekend($date) {
+    $weekDay = date('w', strtotime($date));
+    return ($weekDay == WEEKEND_START_DAY || $weekDay == (WEEKEND_START_DAY + 1) % 7);
+  }
+
+  // isHoliday determines if $date falls on a holiday.
+  static function isHoliday($date) {
+    global $i18n;
+    // $date is expected as string in DB_DATEFORMAT.
+    $month = date('m', strtotime($date));
+    $day = date('d', strtotime($date));
+    if (in_array($month.'/'.$day, $i18n->holidays))
+      return true;
+
+    return false;
+  }
+
   // isValidTime validates a value as a time string.
   static function isValidTime($value) {
     if (strlen($value)==0 || !isset($value)) return false;
@@ -69,18 +87,15 @@ class ttTimeHelper {
     if ($value == '24:00' || $value == '2400') return true;
 
     if (preg_match('/^([0-1]{0,1}[0-9]|2[0-3]):?[0-5][0-9]$/', $value )) { // 0:00 - 23:59, 000 - 2359
-      if ('00:00' == ttTimeHelper::normalizeDuration($value))
-        return false;
       return true;
     }
     if (preg_match('/^([0-1]{0,1}[0-9]|2[0-4])h?$/', $value )) { // 0, 1 ... 24
-      if ('00:00' == ttTimeHelper::normalizeDuration($value))
-        return false;
       return true;
     }
-    if (preg_match('/^([0-1]{0,1}[0-9]|2[0-3])?[.][0-9]{1,4}h?$/', $value )) { // decimal values like 0.5, 1.25h, ... .. 23.9999h
-      if ('00:00' == ttTimeHelper::normalizeDuration($value))
-        return false;
+
+    global $user;
+    $localizedPattern = '/^([0-1]{0,1}[0-9]|2[0-3])?['.$user->decimal_mark.'][0-9]{1,4}h?$/';
+    if (preg_match($localizedPattern, $value )) { // decimal values like 0.5, 1.25h, ... .. 23.9999h (or with comma)
       return true;
     }
 
@@ -92,6 +107,10 @@ class ttTimeHelper {
     $time_value = $value;
 
     // If we have a decimal format - convert to time format 00:00.
+    global $user;
+    if ($user->decimal_mark == ',')
+      $time_value = str_replace (',', '.', $time_value);
+
     if((strpos($time_value, '.') !== false) || (strpos($time_value, 'h') !== false)) {
       $val = floatval($time_value);
       $mins = round($val * 60);