33# annertech-ddev
44# teamwork-api
55
6- # # Description: Log time to a Teamwork task
6+ # # Description: Log time to a Teamwork task (rounded)
77# # Usage: timelog [-v] [-b|-u] [-t task_id] <time> "<comment>"
88# # Example: ddev timelog 1h15m "Code review"
9+ # # Example: ddev timelog $(timew summary $TASK_ID | tail -2 | head -1 | xargs)
910# # Example: ddev timelog -b 1h15m "Client work (billable)"
1011# # Example: ddev timelog -u 30m "Internal meeting (unbillable)"
1112# # Aliases: timelog, timeslip
4748TIME_INPUT=$1
4849COMMENT=$2
4950
51+ # Round up to nearest 15-minute interval
52+ round_to_15min () {
53+ local minutes=$1
54+ local remainder=$(( minutes % 15 ))
55+
56+ if [ $remainder -eq 0 ]; then
57+ echo " $minutes "
58+ else
59+ echo $(( minutes + (15 - remainder) ))
60+ fi
61+ }
62+
5063# Parse time input into total minutes
51- # Supports: "1h15m", "75m", "1.25" (decimal hours), "75" (plain minutes)
64+ # Supports: "1h15m", "75m", "1.25" (decimal hours), "75" (plain minutes), "H:MM:SS" (timewarrior format)
5265parse_time () {
5366 local input=" $1 "
5467 local total=0
5568
56- if [[ " $input " =~ ^([0-9]+)h([0-9]+)m$ ]]; then
69+ if [[ " $input " =~ ^([0-9]+):([0-9]+):([0-9]+)$ ]]; then
70+ # Format: H:MM:SS (timewarrior format - ignores seconds)
71+ total=$(( ${BASH_REMATCH[1]} * 60 + ${BASH_REMATCH[2]} ))
72+ elif [[ " $input " =~ ^([0-9]+)h([0-9]+)m$ ]]; then
5773 # Format: 1h15m
5874 total=$(( ${BASH_REMATCH[1]} * 60 + ${BASH_REMATCH[2]} ))
5975 elif [[ " $input " =~ ^([0-9]+)h$ ]]; then
@@ -71,10 +87,13 @@ parse_time() {
7187 total=$input
7288 else
7389 echo " Invalid time format: $input "
74- echo " Supported formats: 1h15m, 75m, 1.25 (decimal hours), 75 (plain minutes)"
90+ echo " Supported formats: 1h15m, 75m, 1.25 (decimal hours), 75 (plain minutes), H:MM:SS "
7591 exit 1
7692 fi
7793
94+ # Round up to nearest 15-minute interval
95+ total=$( round_to_15min " $total " )
96+
7897 echo " $total "
7998}
8099
187206 else
188207 echo " Error: API returned HTTP $RESPONSE "
189208 fi
190- fi
209+ fi
0 commit comments