return (int)@$time_a[1] + ((int)@$time_a[0]) * 60;
}
- // toDuration - calculates duration between start and finish times in 00:00 format.
- static function toDuration($start, $finish) {
- $duration_minutes = ttTimeHelper::toMinutes($finish) - ttTimeHelper::toMinutes($start);
- if ($duration_minutes <= 0) return false;
-
- $hours = (string)((int)($duration_minutes / 60));
- $mins = (string)($duration_minutes % 60);
+ // toAbsDuration - converts a number of minutes to format 00:00
+ // even if $minutes is negative.
+ static function toAbsDuration($minutes){
+ $hours = (string)((int)abs($minutes / 60));
+ $mins = (string)(abs($minutes % 60));
if (strlen($hours) == 1)
$hours = '0'.$hours;
if (strlen($mins) == 1)
return $hours.':'.$mins;
}
+ // toDuration - calculates duration between start and finish times in 00:00 format.
+ static function toDuration($start, $finish) {
+ $duration_minutes = ttTimeHelper::toMinutes($finish) - ttTimeHelper::toMinutes($start);
+ if ($duration_minutes <= 0) return false;
+
+ return ttTimeHelper::toAbsDuration($duration_minutes);
+ }
+
// The to12HourFormat function converts a 24-hour time value (such as 15:23) to 12 hour format (03:23 PM).
static function to12HourFormat($value) {
if ('24:00' == $value) return '12:00 AM';
return 0;
}
+ // getTimeForMonth - gets total time for a user for a given month.
+ static function getTimeForMonth($user_id, $date){
+ import('Period');
+ $mdb2 = getConnection();
+
+ $period = new Period(INTERVAL_THIS_MONTH, $date);
+ $sql = "select sum(time_to_sec(duration)) as sm from tt_log where user_id = $user_id and date >= '".$period->getBeginDate(DB_DATEFORMAT)."' and date <= '".$period->getEndDate(DB_DATEFORMAT)."' and status = 1";
+ $res = $mdb2->query($sql);
+ if (!is_a($res, 'PEAR_Error')) {
+ $val = $res->fetchRow();
+ return sec_to_time_fmt_hm($val['sm']);
+ }
+ return 0;
+ }
+
// getUncompleted - retrieves an uncompleted record for user, if one exists.
static function getUncompleted($user_id) {
$mdb2 = getConnection();
$mdb2 = getConnection();
$client_field = null;
- if (in_array('cl', explode(',', $user->plugins)))
+ if ($user->isPluginEnabled('cl'))
$client_field = ", c.name as client";
$left_joins = " left join tt_projects p on (l.project_id = p.id)".
" left join tt_tasks t on (l.task_id = t.id)";
- if (in_array('cl', explode(',', $user->plugins)))
+ if ($user->isPluginEnabled('cl'))
$left_joins .= " left join tt_clients c on (l.client_id = c.id)";
$sql = "select l.id as id, TIME_FORMAT(l.start, $sql_time_format) as start,