Commit c06da04b8613bf389cad27e88fd072297b008c38

Authored by Georg Hopp
1 parent d4093e9e

fix time output in timesheets from taskwarrior

... ... @@ -19,4 +19,9 @@ function extracttime() {
19 19 fi
20 20 }
21 21
  22 +function formattime() {
  23 + days=${1%%:*}
  24 + printf "%03dd %s" ${days:-0} ${1#*:}
  25 +}
  26 +
22 27 # vim: set et ts=4 sw=4:
... ...
1 1 #!/bin/zsh
2 2
3   -function tasktimes() {
  3 +function duration() {
4 4 [[ $# -eq 0 ]] && return 1
  5 + task $1 info|\
  6 + sed 's/\([^ ]*\) \([^ ]*\).*duration: \(\([0-9]*\)d \)\?\([^)]*\).*/\1_\2|\4:\5/;te;d;:e'
  7 +}
5 8
6   - local KEY=${2:-\\1}
7   - local T
8   - local D='([0-9]{4}-[0-9]{2}-[0-9]{2})'
9   - local N='([0-9]+)'
10   - local EXPR='s/'$D'.*PT('$N'H)?('$N'M)?('$N').*/'${KEY}':\3:\5:\7/;te;d;:e'
11   -
12   - task $1 info | sed -r ${EXPR} | awk -F: '
13   - {
14   - s = (d[$1][2] + $4) % 60
15   - _m = int((d[$1][2] + $4) / 60)
16   - m = (d[$1][1] + $3 + _m) % 60
17   - _h = int((d[$1][1] + $3 + _m) / 60)
18   - d[$1][0] += $2 + _h
19   - d[$1][1] = m
20   - d[$1][2] = s
21   - }
22   - END {
23   - for(i in d)
24   - printf("%s:%d:%d:%d\n", i, d[i][0], d[i][1], d[i][2])
25   - }' | sort -t: -k1
  9 +function tasktimes() {
  10 + [[ $# -eq 0 ]] && return 1
  11 + duration $1
26 12 }
27 13
28 14 function tasktimestotal() {
29   - tasktimes $1 TOTAL
  15 + set -- $(duration $1)
  16 +
  17 + # == Total calculation ==
  18 + DAYS=0
  19 + TI=0
  20 + for dur; do
  21 + # first skip key
  22 + key=${dur%%|*}
  23 + dur=${dur#*|}
  24 +
  25 + days=${dur%%:*}
  26 + DAYS=$((DAYS+${days:-0}))
  27 +
  28 + ti=$(printf "1970-01-01 %s" ${dur#*:}|xargs -d '\n' date +%s -u -d)
  29 + TI=$((TI+$ti))
  30 +
  31 + if [[ $TI -ge 86400 ]]; then
  32 + # bigger than a day?
  33 + DAYS=$((DAYS+1))
  34 + TI=$((TI-86400))
  35 + fi
  36 + done
  37 + TI="$(date -u -d@${TI} +%X)"
  38 + echo "${DAYS}:${TI}"
  39 + # == End Total Calculation ==
30 40 }
31 41
32 42 function taskdescription() {
... ...
... ... @@ -7,11 +7,14 @@ source $0:A:h/ttyhelper.sh
7 7
8 8 function printtimes() {
9 9 local T
10   - for T in $@
  10 + for T
11 11 do
12   - extracttime $T
13   - printf "%37s%-4s%10s: %s\n" "spent - " "$(date -d "$TIMEKEY" +%a)" \
14   - $TIMEKEY $TIME
  12 + key=${T%%|*}
  13 + dur=${T#*|}
  14 + date="$(date -u -d "${key//_/ }" +%c)"
  15 + ti=$(printf "1970-01-01 %s" ${dur#*:}|xargs -d '\n' date +%X -u -d)
  16 + TIME="$(formattime ${dur})"
  17 + printf "%50s: %14s\n" "${date}" $ti
15 18 done
16 19 }
17 20
... ... @@ -23,14 +26,14 @@ function showall() {
23 26 printf "%s %s %s %s %s\n" \
24 27 "$(underline -16 project)" \
25 28 "$(underline -35 description)" \
26   - "$(underline -8 spent)" \
  29 + "$(underline -13 spent)" \
27 30 "$(underline -10 completed)" \
28 31 "$(underline -10 entered)"
29 32
30 33 for UUID in $@
31 34 do
32   - extracttime $(tasktimes $UUID TOTAL)
33   - printf "%-16s %-35s %-10s %-10s %-8s\n" \
  35 + TIME="$(formattime $(tasktimestotal $UUID))"
  36 + printf "%-16s %-35s %13s %-10s %-10s\n" \
34 37 "$(truncate "$(taskproject $UUID)" 16)" \
35 38 "$(truncate "$(taskdescription $UUID)" 35)" \
36 39 "$(bold "" "$TIME")" \
... ... @@ -66,14 +69,17 @@ function timesheet() {
66 69 "$(bold "" "Blocking tasks")" \
67 70 "${BLOCKING}"
68 71
  72 + halfyear="entry.after:$(date -d '6 month ago' +%F)"
  73 + twoyears="entry.after:$(date -d '2 years ago' +%F)"
  74 +
69 75 printf "%s%s\n\n%s%s\n%s\n\n%s\n\n%s\n" \
70 76 "$(bold "" "Summary")" \
71 77 "$(task rc._forcecolor=on $@ summary 2>/dev/null)" \
72 78 "$(bold "" "History")" \
73   - "$(task rc._forcecolor=on $@ history 2>/dev/null)" \
74   - "$(task rc._forcecolor=on $@ ghistory 2>/dev/null)" \
75   - "$(task rc._forcecolor=on $@ burndown.daily 2>/dev/null)" \
76   - "$(task rc._forcecolor=on $@ burndown 2>/dev/null)"
  79 + "$(task rc._forcecolor=on $@ ${halfyear} history 2>/dev/null)" \
  80 + "$(task rc._forcecolor=on $@ ${halfyear} ghistory 2>/dev/null)" \
  81 + "$(task rc._forcecolor=on $@ ${halfyear} burndown.daily 2>/dev/null)" \
  82 + "$(task rc._forcecolor=on $@ ${twoyears} burndown 2>/dev/null)"
77 83 }
78 84
79 85 function usage() {
... ...
Please register or login to post a comment