26 lines
696 B
Bash
Executable File

#!/bin/bash
shift_data=$(aggietimed -s /run/user/1000/aggietimed.sock --action current-shift 2>&1)
if [[ ${shift_data} == "null" ]]; then
echo '{"active": false, "err": false}'
exit
fi
now=$(date +%s)
start=$(date --date=$(echo $shift_data | jq '.start' -r) +%s)
delta=$(( now - start ))
fallback=$(date --date="" +%s)
if [[ $start == $fallback ]]; then
echo '{"active": false, "err": true}'
exit
fi
hours=$(( delta / 3600 ))
minutes=$( printf "%02d" $(( (delta - (hours * 3600)) / 60 )))
seconds=$( printf "%02d" $(( delta - (hours * 3600) - (minutes * 60) )))
echo "{\"active\": true, \"hours\": \"$hours\", \"minutes\": \"$minutes\", \"seconds\": \"$seconds\", \"err\": false}"