From: Nik Okuntseff Date: Sat, 27 Apr 2019 15:16:45 +0000 (+0000) Subject: Adjusted monthly quotas plugin to use configurable holidays. X-Git-Tag: timetracker_1.19-1~37 X-Git-Url: http://wagnertech.de/git?p=timetracker.git;a=commitdiff_plain;h=19f479eb795f39d331fbfe33ab20534112555630 Adjusted monthly quotas plugin to use configurable holidays. --- diff --git a/WEB-INF/lib/form/Calendar.class.php b/WEB-INF/lib/form/Calendar.class.php index f160cfa6..d3845e8b 100644 --- a/WEB-INF/lib/form/Calendar.class.php +++ b/WEB-INF/lib/form/Calendar.class.php @@ -171,16 +171,9 @@ class Calendar extends FormElement { $stl_cell = ' class="CalendarDay"'; } - // Handle holidays. - // Prepare a date to check in DB_DATEFORMAT. - $date_to_check = "$thisyear-"; - if (strlen($thismonth) == 1) $date_to_check .= '0'; - $date_to_check .= "$thismonth-"; - if (strlen($start_date+$j) == 1) $date_to_check .= '0'; - $date_to_check .= $start_date+$j; - - // Check if it falls on a holiday. - if (ttTimeHelper::isHoliday2($date_to_check)) { + // holidays + $date_to_check = ttTimeHelper::dateInDatabaseFormat($thisyear, $thismonth, $start_date+$j); + if (ttTimeHelper::isHoliday($date_to_check)) { $stl_cell = ' class="CalendarDayHoliday"'; $stl_link = ' class="CalendarLinkHoliday"'; } diff --git a/WEB-INF/lib/ttTimeHelper.class.php b/WEB-INF/lib/ttTimeHelper.class.php index 2b5b39bc..6fd816e0 100644 --- a/WEB-INF/lib/ttTimeHelper.class.php +++ b/WEB-INF/lib/ttTimeHelper.class.php @@ -40,22 +40,6 @@ 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; - - return false; - } - - // isHoliday determines if $date falls on a holiday. - static function isHoliday2($date) { - global $user; $holidays = $user->getHolidays(); if (!$holidays) @@ -88,6 +72,16 @@ class ttTimeHelper { 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; diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index 7efa4d66..6710c5c8 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.19.4.4992 | Copyright © Anuko | +  Anuko Time Tracker 1.19.4.4993 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/plugins/MonthlyQuota.class.php b/plugins/MonthlyQuota.class.php index 21854672..c8559ad4 100644 --- a/plugins/MonthlyQuota.class.php +++ b/plugins/MonthlyQuota.class.php @@ -104,7 +104,7 @@ class MonthlyQuota { // Iterate from 1st up to selected date. $workdaysFrom1st = 0; for ($i = 1; $i <= $selected_date->mDate; $i++) { - $date = "$selected_date->mYear-$selected_date->mMonth-$i"; + $date = ttTimeHelper::dateInDatabaseFormat($selected_date->mYear, $selected_date->mMonth, $i); if (!ttTimeHelper::isWeekend($date) && !ttTimeHelper::isHoliday($date)) { $workdaysFrom1st++; } @@ -139,6 +139,7 @@ class MonthlyQuota { // Iterate through the entire month. for ($i = 1; $i <= $daysInMonth; $i++) { $date = "$year-$month-$i"; + $date = ttTimeHelper::dateInDatabaseFormat($year, $month, $i); if (!ttTimeHelper::isWeekend($date) && !ttTimeHelper::isHoliday($date)) { $workdaysInMonth++; }