bin:timetracking: stdin, curr year, soft columns
This commit is contained in:
@@ -1,26 +1,34 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
YEAR="$(date "+%Y")"
|
|
||||||
EARLIEST_MOD_WEEK="$(date "+%V" --date="14 days ago")"
|
EARLIEST_MOD_WEEK="$(date "+%V" --date="14 days ago")"
|
||||||
typeset -A WEEKS
|
typeset -A WEEKS
|
||||||
|
|
||||||
# gather times
|
if [[ -t 0 ]]; then
|
||||||
IFS=$'\n'
|
times="$(xclip -sel c -o)"
|
||||||
for line in $(xclip -sel c -o | grep $'\t' | tail -n +2); do
|
else
|
||||||
# csv fields (1-bases)
|
times="$(cat)"
|
||||||
end="11,12"
|
fi
|
||||||
start="3,4"
|
times="$(<<<"$times" grep $'\t' | tail -n +2)"
|
||||||
|
YEAR="$(tail -2 <<<"$times" | head -1 | grep -Eo "[0-9]{4}" | head -1)"
|
||||||
|
|
||||||
# get relevant parts and format to ISO 8601'ish format
|
# get relevant parts, format to ISO 8601'ish format and calculate difference
|
||||||
end="$(printf "%s" "$line" | cut -d$'\t' -f"$end" | sed -E 's/^....(..)\.(..)\.(.{4}) \t(.*) $/\3-\2-\1 \4/')"
|
IFS=$'\n'
|
||||||
|
for line in $times; do
|
||||||
|
# gather times
|
||||||
|
times="$(<<<"$line" \
|
||||||
|
grep -Eo $'[0-9. \t:]{18}' \
|
||||||
|
| sed -E 's/.(..)\.(..)\.(.{4}) \t(.*)/\3-\2-\1 \4/'
|
||||||
|
)"
|
||||||
|
|
||||||
|
end="$(<<<"$times" tail -1)"
|
||||||
# check for valid end date & time in this year
|
# check for valid end date & time in this year
|
||||||
[[ $end ]] && [[ $end != $'\t' ]] || continue
|
[[ $end ]] && [[ $end != $'\t' ]] || continue
|
||||||
[[ ${end%%-*} = $YEAR ]] || continue
|
[[ ${end%%-*} = $YEAR ]] || continue
|
||||||
|
|
||||||
|
start="$(<<<"$times" head -1)"
|
||||||
|
|
||||||
# convert to UNIX timestamp
|
# convert to UNIX timestamp
|
||||||
end="$(date --date="$end" "+%s")"
|
end="$(date --date="$end" "+%s")"
|
||||||
|
|
||||||
# get relevant parts and format to ISO 8601'ish format, then UNIX timestamp
|
|
||||||
start="$(printf "%s" "$line" | cut -d$'\t' -f"$start" | sed -E 's/^....(..)\.(..)\.(.{4}) \t(.*) $/\3-\2-\1 \4/')"
|
|
||||||
start="$(date --date="$start" "+%s")"
|
start="$(date --date="$start" "+%s")"
|
||||||
|
|
||||||
diff=$((end - start))
|
diff=$((end - start))
|
||||||
|
|||||||
Reference in New Issue
Block a user