X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/timetracker.git/blobdiff_plain/05f0dada8939fad19e44c9ff26bad6ae578e34cc..040c6516659e15f360159859b783e3722e86f370:/WEB-INF/lib/ttTimeHelper.class.php diff --git a/WEB-INF/lib/ttTimeHelper.class.php b/WEB-INF/lib/ttTimeHelper.class.php index 9ad64fc4..6fd816e0 100644 --- a/WEB-INF/lib/ttTimeHelper.class.php +++ b/WEB-INF/lib/ttTimeHelper.class.php @@ -40,19 +40,48 @@ class ttTimeHelper { // isHoliday determines if $date falls on a holiday. static function isHoliday($date) { global $user; - global $i18n; - if (!$user->show_holidays) return false; - - // $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; + $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; + } + + // dateInDatabaseFormat prepares a date string in DB_DATEFORMAT out of year, month, and day. + static function dateInDatabaseFormat($year, $month, $day) { + $date = "$year-"; + if (strlen($month) == 1) $date .= '0'; + $date .= "$month-"; + if (strlen($day) == 1) $date .= '0'; + $date .= $day; + return $date; + } + // isValidTime validates a value as a time string. static function isValidTime($value) { if (strlen($value)==0 || !isset($value)) return false; @@ -189,7 +218,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);