projects
/
timetracker.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
189e8b9
)
Initial work done to support negative durations, some issues remain.
author
Nik Okuntseff
<support@anuko.com>
Fri, 19 Apr 2019 20:02:40 +0000
(20:02 +0000)
committer
Nik Okuntseff
<support@anuko.com>
Fri, 19 Apr 2019 20:02:40 +0000
(20:02 +0000)
WEB-INF/lib/common.lib.php
patch
|
blob
|
history
WEB-INF/lib/ttChartHelper.class.php
patch
|
blob
|
history
WEB-INF/lib/ttReportHelper.class.php
patch
|
blob
|
history
WEB-INF/lib/ttTimeHelper.class.php
patch
|
blob
|
history
WEB-INF/templates/footer.tpl
patch
|
blob
|
history
diff --git
a/WEB-INF/lib/common.lib.php
b/WEB-INF/lib/common.lib.php
index
e295075
..
747f3e0
100644
(file)
--- a/
WEB-INF/lib/common.lib.php
+++ b/
WEB-INF/lib/common.lib.php
@@
-143,11
+143,6
@@
function time_to_decimal($val) {
return $decimalTime;
}
return $decimalTime;
}
-function sec_to_time_fmt_hm($sec)
-{
- return sprintf("%d:%02d", $sec / 3600, $sec % 3600 / 60);
-}
-
function magic_quotes_off()
{
$_POST = array_map('stripslashes_deep', $_POST);
function magic_quotes_off()
{
$_POST = array_map('stripslashes_deep', $_POST);
diff --git
a/WEB-INF/lib/ttChartHelper.class.php
b/WEB-INF/lib/ttChartHelper.class.php
index
528fcdb
..
efb30c6
100644
(file)
--- a/
WEB-INF/lib/ttChartHelper.class.php
+++ b/
WEB-INF/lib/ttChartHelper.class.php
@@
-27,6
+27,7
@@
// +----------------------------------------------------------------------+
import('Period');
// +----------------------------------------------------------------------+
import('Period');
+import('ttTimeHelper');
// Definitions for chart types.
define('CHART_PROJECTS', 1);
// Definitions for chart types.
define('CHART_PROJECTS', 1);
@@
-97,7
+98,7
@@
class ttChartHelper {
// Add a string representation of time + percentage to names. Example: "Time Tracker (1:15 - 6%)".
foreach ($result as &$one_val) {
$percent = round(100*$one_val['time']/$total).'%';
// Add a string representation of time + percentage to names. Example: "Time Tracker (1:15 - 6%)".
foreach ($result as &$one_val) {
$percent = round(100*$one_val['time']/$total).'%';
- $one_val['name'] .= ' ('.
sec_to_time_fmt_hm($one_val['time']
).' - '.$percent.')';
+ $one_val['name'] .= ' ('.
ttTimeHelper::minutesToDuration($one_val['time'] / 60
).' - '.$percent.')';
}
// Note: the remaining code here is needed to display labels on the side of the diagram.
}
// Note: the remaining code here is needed to display labels on the side of the diagram.
diff --git
a/WEB-INF/lib/ttReportHelper.class.php
b/WEB-INF/lib/ttReportHelper.class.php
index
9c6dfb0
..
5fd2253
100644
(file)
--- a/
WEB-INF/lib/ttReportHelper.class.php
+++ b/
WEB-INF/lib/ttReportHelper.class.php
@@
-513,7
+513,7
@@
class ttReportHelper {
$res = $mdb2->query($sql);
if (is_a($res, 'PEAR_Error')) die($res->getMessage());
while ($val = $res->fetchRow()) {
$res = $mdb2->query($sql);
if (is_a($res, 'PEAR_Error')) die($res->getMessage());
while ($val = $res->fetchRow()) {
- $time = $val['time'] ?
sec_to_time_fmt_hm($val['time']
) : null;
+ $time = $val['time'] ?
ttTimeHelper::minutesToDuration($val['time'] / 60
) : null;
$rowLabel = ttReportHelper::makeGroupByLabel($val['group_field'], $options);
if ($options['show_cost']) {
$decimalMark = $user->getDecimalMark();
$rowLabel = ttReportHelper::makeGroupByLabel($val['group_field'], $options);
if ($options['show_cost']) {
$decimalMark = $user->getDecimalMark();
@@
-595,7
+595,7
@@
class ttReportHelper {
if (is_a($res, 'PEAR_Error')) die($res->getMessage());
$val = $res->fetchRow();
if (is_a($res, 'PEAR_Error')) die($res->getMessage());
$val = $res->fetchRow();
- $total_time = $val['time'] ?
sec_to_time_fmt_hm($val['time']
) : null;
+ $total_time = $val['time'] ?
ttTimeHelper::minutesToDuration($val['time'] / 60
) : null;
if ($options['show_cost']) {
$total_cost = $val['cost'];
if (!$total_cost) $total_cost = '0.00';
if ($options['show_cost']) {
$total_cost = $val['cost'];
if (!$total_cost) $total_cost = '0.00';
diff --git
a/WEB-INF/lib/ttTimeHelper.class.php
b/WEB-INF/lib/ttTimeHelper.class.php
index
5745128
..
3cef8b4
100644
(file)
--- a/
WEB-INF/lib/ttTimeHelper.class.php
+++ b/
WEB-INF/lib/ttTimeHelper.class.php
@@
-132,17
+132,21
@@
class ttTimeHelper {
if (!isset($duration) || strlen($duration) == 0)
return null; // Value is not set. Caller decides whether it is valid or not.
if (!isset($duration) || strlen($duration) == 0)
return null; // Value is not set. Caller decides whether it is valid or not.
+ // We allow negative durations, similar to negative expenses (installments).
+ $signMultiplier = ttStartsWith($duration, '-') ? -1 : 1;
+ if ($signMultiplier == -1) $duration = ltrim($duration, '-');
+
// Handle whole hours.
if (preg_match('/^\d{1,3}h?$/', $duration )) { // 0 - 999, 0h - 999h
$minutes = 60 * trim($duration, 'h');
// Handle whole hours.
if (preg_match('/^\d{1,3}h?$/', $duration )) { // 0 - 999, 0h - 999h
$minutes = 60 * trim($duration, 'h');
- return $minutes > $max ? false : $minutes;
+ return $minutes > $max ? false : $
signMultiplier * $
minutes;
}
// Handle a normalized duration value.
if (preg_match('/^\d{1,3}:[0-5][0-9]$/', $duration )) { // 0:00 - 999:59
$time_array = explode(':', $duration);
$minutes = (int)@$time_array[1] + ((int)@$time_array[0]) * 60;
}
// Handle a normalized duration value.
if (preg_match('/^\d{1,3}:[0-5][0-9]$/', $duration )) { // 0:00 - 999:59
$time_array = explode(':', $duration);
$minutes = (int)@$time_array[1] + ((int)@$time_array[0]) * 60;
- return $minutes > $max ? false : $minutes;
+ return $minutes > $max ? false : $
signMultiplier * $
minutes;
}
// Handle localized fractional hours.
}
// Handle localized fractional hours.
@@
-153,13
+157,13
@@
class ttTimeHelper {
$duration = str_replace (',', '.', $duration);
$minutes = (int)round(60 * floatval($duration));
$duration = str_replace (',', '.', $duration);
$minutes = (int)round(60 * floatval($duration));
- return $minutes > $max ? false : $minutes;
+ return $minutes > $max ? false : $
signMultiplier * $
minutes;
}
// Handle minutes. Some users enter durations like 10m (meaning 10 minutes).
if (preg_match('/^\d{1,5}m$/', $duration )) { // 0m - 99999m
$minutes = (int) trim($duration, 'm');
}
// Handle minutes. Some users enter durations like 10m (meaning 10 minutes).
if (preg_match('/^\d{1,5}m$/', $duration )) { // 0m - 99999m
$minutes = (int) trim($duration, 'm');
- return $minutes > $max ? false : $minutes;
+ return $minutes > $max ? false : $
signMultiplier * $
minutes;
}
// Everything else is not a valid duration.
}
// Everything else is not a valid duration.
@@
-169,16
+173,17
@@
class ttTimeHelper {
// minutesToDuration converts an integer number of minutes into duration string.
// Formats returned HH:MM, HHH:MM, HH, or HHH.
static function minutesToDuration($minutes, $abbreviate = false) {
// minutesToDuration converts an integer number of minutes into duration string.
// Formats returned HH:MM, HHH:MM, HH, or HHH.
static function minutesToDuration($minutes, $abbreviate = false) {
- if ($minutes < 0) return false;
+ $sign = $minutes > 0 ? '' : '-';
+ $minutes = abs($minutes);
$hours = (string) (int)($minutes / 60);
$mins = (string) round(fmod($minutes, 60));
if (strlen($mins) == 1)
$mins = '0' . $mins;
if ($abbreviate && $mins == '00')
$hours = (string) (int)($minutes / 60);
$mins = (string) round(fmod($minutes, 60));
if (strlen($mins) == 1)
$mins = '0' . $mins;
if ($abbreviate && $mins == '00')
- return $hours;
+ return $
sign.$
hours;
- return $hours.':'.$mins;
+ return $
sign.$
hours.':'.$mins;
}
// toMinutes - converts a time string in format 00:00 to a number of minutes.
}
// toMinutes - converts a time string in format 00:00 to a number of minutes.
@@
-552,7
+557,7
@@
class ttTimeHelper {
$res = $mdb2->query($sql);
if (!is_a($res, 'PEAR_Error')) {
$val = $res->fetchRow();
$res = $mdb2->query($sql);
if (!is_a($res, 'PEAR_Error')) {
$val = $res->fetchRow();
- return
sec_to_time_fmt_hm($val['sm']
);
+ return
ttTimeHelper::minutesToDuration($val['sm'] / 60
);
}
return false;
}
}
return false;
}
@@
-574,7
+579,7
@@
class ttTimeHelper {
$res = $mdb2->query($sql);
if (!is_a($res, 'PEAR_Error')) {
$val = $res->fetchRow();
$res = $mdb2->query($sql);
if (!is_a($res, 'PEAR_Error')) {
$val = $res->fetchRow();
- return
sec_to_time_fmt_hm($val['sm']
);
+ return
ttTimeHelper::minutesToDuration($val['sm'] / 60
);
}
return false;
}
}
return false;
}
@@
-596,7
+601,7
@@
class ttTimeHelper {
$res = $mdb2->query($sql);
if (!is_a($res, 'PEAR_Error')) {
$val = $res->fetchRow();
$res = $mdb2->query($sql);
if (!is_a($res, 'PEAR_Error')) {
$val = $res->fetchRow();
- return
sec_to_time_fmt_hm($val['sm']
);
+ return
ttTimeHelper::minutesToDuration($val['sm'] / 60
);
}
return false;
}
}
return false;
}
diff --git
a/WEB-INF/templates/footer.tpl
b/WEB-INF/templates/footer.tpl
index
8a059ce
..
b41511a
100644
(file)
--- a/
WEB-INF/templates/footer.tpl
+++ b/
WEB-INF/templates/footer.tpl
@@
-12,7
+12,7
@@
<br>
<table cellspacing="0" cellpadding="4" width="100%" border="0">
<tr>
<br>
<table cellspacing="0" cellpadding="4" width="100%" border="0">
<tr>
- <td align="center"> Anuko Time Tracker 1.19.1.496
2
| Copyright © <a href="https://www.anuko.com/lp/tt_3.htm" target="_blank">Anuko</a> |
+ <td align="center"> Anuko Time Tracker 1.19.1.496
3
| Copyright © <a href="https://www.anuko.com/lp/tt_3.htm" target="_blank">Anuko</a> |
<a href="https://www.anuko.com/lp/tt_4.htm" target="_blank">{$i18n.footer.credits}</a> |
<a href="https://www.anuko.com/lp/tt_5.htm" target="_blank">{$i18n.footer.license}</a> |
<a href="https://www.anuko.com/lp/tt_7.htm" target="_blank">{$i18n.footer.improve}</a>
<a href="https://www.anuko.com/lp/tt_4.htm" target="_blank">{$i18n.footer.credits}</a> |
<a href="https://www.anuko.com/lp/tt_5.htm" target="_blank">{$i18n.footer.license}</a> |
<a href="https://www.anuko.com/lp/tt_7.htm" target="_blank">{$i18n.footer.improve}</a>