From d750614c66f49bf68fd660a67a7d3805578238fc Mon Sep 17 00:00:00 2001 From: Nik Okuntseff Date: Sun, 21 Apr 2019 16:09:34 +0000 Subject: [PATCH] Fixed monthly quotas for negative hours. --- WEB-INF/lib/ttTimeHelper.class.php | 5 ++++- WEB-INF/templates/footer.tpl | 2 +- quotas.php | 6 ++++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/WEB-INF/lib/ttTimeHelper.class.php b/WEB-INF/lib/ttTimeHelper.class.php index 8142a266..44d96785 100644 --- a/WEB-INF/lib/ttTimeHelper.class.php +++ b/WEB-INF/lib/ttTimeHelper.class.php @@ -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 diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index 9afec79a..2524785e 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.19.1.4966 | Copyright © Anuko | +  Anuko Time Tracker 1.19.1.4967 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/quotas.php b/quotas.php index 1f376190..b6d63fa3 100644 --- a/quotas.php +++ b/quotas.php @@ -74,12 +74,14 @@ $quota = new MonthlyQuota(); if ($request->isPost()){ // Validate user input. - if (false === ttTimeHelper::postedDurationToMinutes($request->getParameter('workdayHours'))) + $workdayMinutes = ttTimeHelper::postedDurationToMinutes($request->getParameter('workdayHours')); + if (false === $workdayMinutes || $workdayMinutes <= 0 ) $err->add($i18n->get('error.field'), $i18n->get('form.quota.workday_hours')); for ($i = 0; $i < count($months); $i++){ $val = $request->getParameter($months[$i]); - if (false === ttTimeHelper::postedDurationToMinutes($val, 44640/*24*60*31*/)) + $monthMinutes = ttTimeHelper::postedDurationToMinutes($val, 44640/*24*60*31*/); + if (false === $monthMinutes || $monthMinutes < 0) $err->add($i18n->get('error.field'), $months[$i]); } // Finished validating user input. -- 2.20.1