Taskw end: Ensure a task don't go on several days

This commit is contained in:
gardouille 2021-10-15 11:45:01 +02:00
parent cb7c5eafc0
commit 26e1884922
Signed by: gardouille
GPG Key ID: E759BAA22501AF32
1 changed files with 12 additions and 3 deletions

15
zshrc
View File

@ -749,9 +749,12 @@ function tiend() {
# Get time tracking's description from all time tracking of this year
local tiend_time_desc=$(timew summary :year :ids | sed -n "s/.*@\(${tiend_time_id} .*\)/\1/p" | sed 's/ */ /g')
# Get time tracking's start day from all time tracking
local tiend_time_start_day=$(timew export | sed -nE "s/^\{\"id\":${tiend_time_id},\"start\":\"([0-9]{4})([0-9]{2})([0-9]{2})T.*end.*/\1-\2-\3/p")
# Check or ask for new end time {{{
if [ -z "${tiend_time_new_end}" ]; then
printf '%b' "Enter the ${MAGENTAB}new end time${RESET} (or new date 'YYYY-MM-DD${REDB}T${RESET}HH:MM:SS') for this time tracking : "
printf '%b' "Enter the ${MAGENTAB}new end time${RESET} (or new date 'YYYY-MM-DD${REDB}T${RESET}HH:MM:SS'; default day is ${tiend_time_start_day}) for this time tracking : "
read -r tiend_time_new_end
fi
# }}}
@ -761,8 +764,14 @@ function tiend() {
# Check confirmation
if printf -- '%s' "${tiend_confirmation:=y}" | grep --quiet --word-regexp -- "y"; then
timew modify end @"${tiend_time_id}" "${tiend_time_new_end}" || return 0
printf '%b' "End time of ${tiend_time_desc} is now ${tiend_time_new_end}."
## If the new end time entered by user contains a "T" (user enter a dateTtime)
if printf -- '%s' "${tiend_time_new_end}" | grep --quiet -- "T"; then
timew modify end @"${tiend_time_id}" "${tiend_time_new_end}" || return 0
printf '%b' "End time of ${tiend_time_desc} is now ${tiend_time_new_end}."
else
timew modify end @"${tiend_time_id}" "${tiend_time_start_day}T${tiend_time_new_end}" || return 0
printf '%b' "End time of ${tiend_time_desc} is now ${tiend_time_start_day}T${tiend_time_new_end}."
fi
fi
# Unset defined variables