X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/timetracker.git/blobdiff_plain/05f0dada8939fad19e44c9ff26bad6ae578e34cc..9819bb63bec83c13dd40ebb2ffc24df5fcfeda33:/WEB-INF/lib/ttTimeHelper.class.php diff --git a/WEB-INF/lib/ttTimeHelper.class.php b/WEB-INF/lib/ttTimeHelper.class.php index 9ad64fc4..2b5b39bc 100644 --- a/WEB-INF/lib/ttTimeHelper.class.php +++ b/WEB-INF/lib/ttTimeHelper.class.php @@ -53,6 +53,41 @@ class ttTimeHelper { return false; } + // isHoliday determines if $date falls on a holiday. + static function isHoliday2($date) { + global $user; + + $holidays = $user->getHolidays(); + if (!$holidays) + return false; + + $holiday_dates = explode(',', $holidays); + foreach ($holiday_dates as $holiDateSpec) { + if (ttTimeHelper::holidayMatch($date, $holiDateSpec)) + return true; + } + return false; + } + + // holidayMatch determines if $date matches a single $holiDateSpec. + static function holidayMatch($date, $holiDateSpec) { + + $dateArray = explode('-', $date); + $holiDateSpecArray = explode('-', $holiDateSpec); + + // Check year. + if ($dateArray[0] != $holiDateSpecArray[0] && $holiDateSpecArray[0] != '****') // **** means all years. + return false; + // Check month. + if ($dateArray[1] != $holiDateSpecArray[1]) + return false; + // Check day. + if ($dateArray[2] != $holiDateSpecArray[2]) + return false; + + return true; + } + // isValidTime validates a value as a time string. static function isValidTime($value) { if (strlen($value)==0 || !isset($value)) return false; @@ -189,7 +224,7 @@ 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, '-'); + if ($signMultiplier == -1) $value = ltrim($value, '-'); $time_a = explode(':', $value); return $signMultiplier * ((int)@$time_a[1] + ((int)@$time_a[0]) * 60);