DTime Task::totalTimeCurrentDay() const { DateTime today = DateTime::today(); DateTime tomorrow = today.addDays(1); DTime totalTime; if (childCount() == 0) { for (vector<TaskLog*>::iterator iterLog = _logs->begin(); iterLog != _logs->end(); iterLog++) { TaskLog* log = *iterLog; if (*log->start >= today) { if (*log->end < tomorrow) { totalTime.add((*log->end) - (*log->start)); } else { totalTime.add((*log->end) - tomorrow); } } } } else { vector<Task*> subtasks = children(); for (vector<Task*>::iterator iter = subtasks.begin(); iter != subtasks.end(); iter++) { Task* sub = *iter; totalTime.add(sub->totalTimeCurrentDay()); } } return totalTime; }
DTime Task::totalTime() const { DTime result; for (vector<TaskLog*>::iterator iterLog = _logs->begin(); iterLog != _logs->end(); iterLog++) { TaskLog* log = *iterLog; result.add((*log->end) - (*log->start)); } vector<Task*> subtasks = children(); for (vector<Task*>::iterator iter = subtasks.begin(); iter != subtasks.end(); iter++) { Task* sub = *iter; result.add(sub->totalTime()); } return result; }
DTime Task::totalTimeCurrentWeek() const { DateTime startDayWeek = DateTime::startDayOfWeek(); DateTime startDayOfNextWeek = DateTime::startDayOfNextWeek(); DTime totalTime; if (childCount() == 0) { for (vector<TaskLog*>::iterator iterLog = _logs->begin(); iterLog != _logs->end(); iterLog++) { TaskLog* log = *iterLog; if ((*(log->start) >= startDayWeek) && (*(log->end) < startDayOfNextWeek)) { totalTime.add((*log->end) - (*log->start)); } } } else { vector<Task*> subtasks = children(); for (vector<Task*>::iterator iter = subtasks.begin(); iter != subtasks.end(); iter++) { Task* sub = *iter; totalTime.add(sub->totalTimeCurrentWeek()); } } return totalTime; }