From 26e1884922f4a74862b5498f7757a027e91876df Mon Sep 17 00:00:00 2001 From: Gardouille Date: Fri, 15 Oct 2021 11:45:01 +0200 Subject: [PATCH] Taskw end: Ensure a task don't go on several days --- zshrc | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/zshrc b/zshrc index 3eb7314..b8a45e9 100644 --- a/zshrc +++ b/zshrc @@ -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