summaryrefslogtreecommitdiffstats
path: root/.local/bin/overtid
blob: 85043c6e34d31f15ec356b3e05370e71bf300858 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/bin/bash

# variables
time_input="$1"
time_start="09:00"
time_end="17:30"
start="$(date -d "Yesterday $time_input" "+%s")"

# check for arguments
if [ $# -eq 0 ]; then
	printf "Decimal overtime calculator\\nUsage: %s HH:MM\\n" "${0##*/}"
	exit 1
fi

# main logic
if [ "${time_start:0:2}" -gt "${time_input:0:2}" ]; then
	end="$(date -d "Yesterday $time_start" "+%s")"
	printf "Early start: %s hours\\n" "$(date -d\@$((end - start)) -u +'scale=2; %H + %M/60' | bc)"
else
	end="$(date -d "Yesterday $time_end" "+%s")"
	printf "Late finish: %s hours\\n" "$(date -d\@$((start - end)) -u +'scale=2; %H + %M/60' | bc)"
fi