summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter2022-10-15 12:43:48 +0100
committerPeter2022-10-15 12:43:48 +0100
commit65f0ff89a05b54f9f81605aed4aa06f47c9fe46e (patch)
treedfe37bc44b3f78325061d08d9437368415ee6112
parentf16fd4298dd5e7bf7f02ae6e1651c068575469c4 (diff)
downloaddotfiles-65f0ff89a05b54f9f81605aed4aa06f47c9fe46e.tar.gz
dotfiles-65f0ff89a05b54f9f81605aed4aa06f47c9fe46e.tar.bz2
dotfiles-65f0ff89a05b54f9f81605aed4aa06f47c9fe46e.zip
Add overtime script
-rwxr-xr-x.local/bin/overtid23
1 files changed, 23 insertions, 0 deletions
diff --git a/.local/bin/overtid b/.local/bin/overtid
new file mode 100755
index 0000000..3e16dad
--- /dev/null
+++ b/.local/bin/overtid
@@ -0,0 +1,23 @@
+#!/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
+ script="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
+ printf "Decimal overtime calculator\\nUsage: %s HH:MM\\n" "${script%.*}"
+ 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