5

I'm trying to use taskwarrior to track time for billing purposes.

To do that I'm trying to generate a report showing the hours spend on each task. The standard completed report gives the Created and Completed dates but not times, so I cant see how many hours were spent on the task.

$ task completed project:test

ID UUID     Created    Completed  Age   Project Description
 - fed3daca 2019-09-29 2019-09-29 10min test    test1
 - 31a8f13e 2019-09-29 2019-09-29 1min  test    test2      

2 tasks

Is this something taskwarrior can do? Thanks

2 Answers2

3

I don't think taskwarrior can create those reports by itself, but you could use timewarrior to do that.

After you set up timewarrior, the time spent on each task will be tracked. Example:

➜  ~ task add reply on stack overflow 
Created task 341.
➜  ~ task start 341
Starting task 81b73133 'reply on stack overflow'.
Started 1 task.
Tracking "reply on stack overflow"
  Started 2020-04-10T12:07:58
  Current                  59
  Total               0:00:01
➜  ~ task 341 done 
Completed task 81b73133 'reply on stack overflow'.
Completed 1 task.
Recorded "reply on stack overflow"
  Started 2020-04-10T12:07:58
  Ended                 09:12
  Total               0:01:14

By default you will see how much time you spent on the task. In case you start and stop the task multiple times or want to see the time you spent on a project or on tasks with a certain tag, you can query timewarrior directly:

➜  ~ timew summary 'reply on stack overflow'

Wk  Date       Day Tags                       Start      End    Time   Total
W15 2020-04-10 Fri reply on stack overflow 12:07:58 12:09:12 0:01:14 0:01:14
                                                                            
                                                                     0:01:14

This shows you the time you spent today on that task. You can also specify a time interval in case you want to see the total time spent on the task/project/tag. Example:

➜  ~ timew summary 2020-01-01 - tomorrow 'reply on stack overflow'

Wk  Date       Day Tags                       Start      End    Time   Total
W15 2020-04-10 Fri reply on stack overflow 12:07:58 12:09:12 0:01:14 0:01:14
                                                                            
                                                                     0:01:14

To see how much time you spent on project test you can just run:

timew summary 2018-01-01 - tomorrow test

This will also include the tasks named 'test' and tasks with the tag test.

Tom Dörr
  • 424
  • 4
  • 14
  • Please post more informative answers. The link you included does not include any instructions how to achieve what's asked in this question. – alec Apr 06 '20 at 02:03
  • Timewarrior is the de facto standard timetracking functionality for Taskwarrior (though there's also a Watson Utils script that provides a Taskwarrior hook) but there's (oddly) no obvious way to see how many hours were spent on a task. – alec Apr 09 '20 at 02:54
  • @alec I just updated my answer, is this what you are looking for? – Tom Dörr Apr 10 '20 at 10:26
  • that's helpful. Is it always necessary to include a date range? Is there no automatic way to say "all the time tracked for this tag"? (I think in timewarrior projects/tasks get turned into "tags".) Having to type the date range each time is cumbersome... and it could be avoided by writing a wrapper function, but it seems odd that the program wouldn't provide a way of doing that on its own. – alec Apr 10 '20 at 15:09
  • 2
    I'm not aware of a build in way to query over the complete date range, but I agree, it would be useful. We could open a github issue. Just so you know: There are the `timew week tag` and `timew month tag` reports, which do set the date range. – Tom Dörr Apr 11 '20 at 23:59
0

As mentioned by Tom Dörr use timewarrior to summarize by tags.

This is the way I do:

  1. Collect the tags by date range, modify the date range for your needs:
    timew tags :week
  2. Remove the headings from the output:
    timew tags :week | tail -n+4
  3. Use awk to separate the fiels by dash and print first field:
    timew tags :week | tail -n+4 | awk 'BEGIN {FS="-"}; {print $1}'

This results in a list of tags for the selected date range, each in one line. Now you can use a script (for example summarize.sh) to loop through these tags to summarize:

#!/bin/bash
while read TAG; do
  [ "${TAG}" = "" ] && continue
  timew summary :week "${TAG}"
done < <(timew tags :week | tail -n+4 | awk 'BEGIN {FS="-"}; {print $1}')

This way you can handle tags containing whitespace also.

At least, run a loop in shell/bash to update permanently, for example every second:

while :; do clear; date; ./summarize.sh; sleep 1; done
ChristophS
  • 498
  • 4
  • 18