Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions commands/host/timelog
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
#annertech-ddev
#teamwork-api

## Description: Log time to a Teamwork task
## Description: Log time to a Teamwork task (rounded)
## Usage: timelog [-v] [-b|-u] [-t task_id] <time> "<comment>"
## Example: ddev timelog 1h15m "Code review"
## Example: ddev timelog $(timew summary $TASK_ID | tail -2 | head -1 | xargs)
## Example: ddev timelog -b 1h15m "Client work (billable)"
## Example: ddev timelog -u 30m "Internal meeting (unbillable)"
## Aliases: timelog, timeslip
Expand Down Expand Up @@ -47,13 +48,28 @@ done
TIME_INPUT=$1
COMMENT=$2

# Round up to nearest 15-minute interval
round_to_15min() {
local minutes=$1
local remainder=$((minutes % 15))

if [ $remainder -eq 0 ]; then
echo "$minutes"
else
echo $(( minutes + (15 - remainder) ))
fi
}

# Parse time input into total minutes
# Supports: "1h15m", "75m", "1.25" (decimal hours), "75" (plain minutes)
# Supports: "1h15m", "75m", "1.25" (decimal hours), "75" (plain minutes), "H:MM:SS" (timewarrior format)
parse_time() {
local input="$1"
local total=0

if [[ "$input" =~ ^([0-9]+)h([0-9]+)m$ ]]; then
if [[ "$input" =~ ^([0-9]+):([0-9]+):([0-9]+)$ ]]; then
# Format: H:MM:SS (timewarrior format - ignores seconds)
total=$(( ${BASH_REMATCH[1]} * 60 + ${BASH_REMATCH[2]} ))
elif [[ "$input" =~ ^([0-9]+)h([0-9]+)m$ ]]; then
# Format: 1h15m
total=$(( ${BASH_REMATCH[1]} * 60 + ${BASH_REMATCH[2]} ))
elif [[ "$input" =~ ^([0-9]+)h$ ]]; then
Expand All @@ -71,10 +87,13 @@ parse_time() {
total=$input
else
echo "Invalid time format: $input"
echo "Supported formats: 1h15m, 75m, 1.25 (decimal hours), 75 (plain minutes)"
echo "Supported formats: 1h15m, 75m, 1.25 (decimal hours), 75 (plain minutes), H:MM:SS"
exit 1
fi

# Round up to nearest 15-minute interval
total=$(round_to_15min "$total")

echo "$total"
}

Expand Down Expand Up @@ -187,4 +206,4 @@ else
else
echo "Error: API returned HTTP $RESPONSE"
fi
fi
fi
30 changes: 30 additions & 0 deletions commands/host/timewarrior-timelog
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash
#ddev-generated
#annertech-ddev
#teamwork-api

## Description: Log timewarrior summary to Teamwork task
## Usage: timewarrior-timelog
## Aliases: twl

branch_name=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)
if [[ $branch_name =~ T-([0-9]+) ]]; then
TASK_ID="${BASH_REMATCH[1]}"
else
echo "No task ID found in the branch name."
read -e -p "Enter task ID: " TASK_ID
if [[ -z "$TASK_ID" ]]; then
echo "Error: Task ID is required."
exit 1
fi
fi

# Get total time from timewarrior
TIME=$(timew summary "$TASK_ID" | tail -2 | head -1 | xargs)

if [[ -z "$TIME" ]]; then
echo "Error: No time entries found for task ID $TASK_ID in timewarrior"
exit 1
fi

ddev timelog "$TIME"