Skip to content

Commit 6464ed6

Browse files
authored
timew automatic logging (#99)
1 parent 98427a1 commit 6464ed6

File tree

2 files changed

+54
-5
lines changed

2 files changed

+54
-5
lines changed

commands/host/timelog

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
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
@@ -47,13 +48,28 @@ done
4748
TIME_INPUT=$1
4849
COMMENT=$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)
5265
parse_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

@@ -187,4 +206,4 @@ else
187206
else
188207
echo "Error: API returned HTTP $RESPONSE"
189208
fi
190-
fi
209+
fi

commands/host/timewarrior-timelog

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env bash
2+
#ddev-generated
3+
#annertech-ddev
4+
#teamwork-api
5+
6+
## Description: Log timewarrior summary to Teamwork task
7+
## Usage: timewarrior-timelog
8+
## Aliases: twl
9+
10+
branch_name=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)
11+
if [[ $branch_name =~ T-([0-9]+) ]]; then
12+
TASK_ID="${BASH_REMATCH[1]}"
13+
else
14+
echo "No task ID found in the branch name."
15+
read -e -p "Enter task ID: " TASK_ID
16+
if [[ -z "$TASK_ID" ]]; then
17+
echo "Error: Task ID is required."
18+
exit 1
19+
fi
20+
fi
21+
22+
# Get total time from timewarrior
23+
TIME=$(timew summary "$TASK_ID" | tail -2 | head -1 | xargs)
24+
25+
if [[ -z "$TIME" ]]; then
26+
echo "Error: No time entries found for task ID $TASK_ID in timewarrior"
27+
exit 1
28+
fi
29+
30+
ddev timelog "$TIME"

0 commit comments

Comments
 (0)