Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions tests/t1011-add-format-date.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env bash

test_description='test TODOTXT_DATE_FORMAT environment variable

Ensure that the date format of creation and completion dates is correct
'
. ./test-lib.sh


unset TODOTXT_DATE_FORMAT
test_todo_session 'default date format with env var unset' <<EOF
>>> todo.sh -t add Solve the halting problem
1 2009-02-13 Solve the halting problem
TODO: 1 added.

>>> todo.sh list
1 2009-02-13 Solve the halting problem
--
TODO: 1 of 1 tasks shown
EOF

export TODOTXT_DATE_FORMAT="%Y-%m-%dT%H:%M:%S%z"
test_todo_session 'ISO-8601 with seconds and timezone' <<EOF
>>> todo.sh -t add Solve the halting problem
2 2009-02-13T04:40:00+0000 Solve the halting problem
TODO: 2 added.

>>> todo.sh list
1 2009-02-13 Solve the halting problem
2 2009-02-13T04:40:00+0000 Solve the halting problem
--
TODO: 2 of 2 tasks shown
EOF

test_todo_session 'ISO-8601 completion date' <<EOF
>>> todo.sh -t done 2
2 x 2009-02-13T04:40:00+0000 2009-02-13T04:40:00+0000 Solve the halting problem
TODO: 2 marked as done.
x 2009-02-13T04:40:00+0000 2009-02-13T04:40:00+0000 Solve the halting problem
TODO: $HOME/todo.txt archived.

>>> todo.sh listall
1 2009-02-13 Solve the halting problem
0 x 2009-02-13T04:40:00+0000 2009-02-13T04:40:00+0000 Solve the halting problem
--
TODO: 1 of 1 tasks shown
DONE: 1 of 1 tasks shown
total 2 of 2 tasks shown
EOF

test_done
10 changes: 8 additions & 2 deletions todo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ $indentedJoinedConfigFileLocations
TODOTXT_DEFAULT_ACTION="" run this when called with no arguments
TODOTXT_SORT_COMMAND="sort ..." customize list output
TODOTXT_FINAL_FILTER="sed ..." customize list after color, P@+ hiding
TODOTXT_DATE_FORMAT="%Y-%m-%d" customize creation/completion date format
TODOTXT_SOURCEVAR=\$DONE_FILE use another source for listcon, listproj
TODOTXT_SIGIL_BEFORE_PATTERN="" optionally allow chars preceding +p / @c
TODOTXT_SIGIL_VALID_PATTERN=.* tweak the allowed chars for +p and @c
Expand Down Expand Up @@ -524,6 +525,7 @@ OVR_TODOTXT_AUTO_ARCHIVE="$TODOTXT_AUTO_ARCHIVE"
OVR_TODOTXT_FORCE="$TODOTXT_FORCE"
OVR_TODOTXT_PRESERVE_LINE_NUMBERS="$TODOTXT_PRESERVE_LINE_NUMBERS"
OVR_TODOTXT_PLAIN="$TODOTXT_PLAIN"
OVR_TODOTXT_DATE_FORMAT="$TODOTXT_DATE_FORMAT"
OVR_TODOTXT_DATE_ON_ADD="$TODOTXT_DATE_ON_ADD"
OVR_TODOTXT_PRIORITY_ON_ADD="$TODOTXT_PRIORITY_ON_ADD"
OVR_TODOTXT_DISABLE_FILTER="$TODOTXT_DISABLE_FILTER"
Expand Down Expand Up @@ -642,6 +644,7 @@ TODOTXT_PLAIN=${TODOTXT_PLAIN:-0}
TODOTXT_FORCE=${TODOTXT_FORCE:-0}
TODOTXT_PRESERVE_LINE_NUMBERS=${TODOTXT_PRESERVE_LINE_NUMBERS:-1}
TODOTXT_AUTO_ARCHIVE=${TODOTXT_AUTO_ARCHIVE:-1}
TODOTXT_DATE_FORMAT=${TODOTXT_DATE_FORMAT:-%Y-%m-%d}
TODOTXT_DATE_ON_ADD=${TODOTXT_DATE_ON_ADD:-0}
TODOTXT_PRIORITY_ON_ADD=${TODOTXT_PRIORITY_ON_ADD:-}
TODOTXT_DEFAULT_ACTION=${TODOTXT_DEFAULT_ACTION:-}
Expand Down Expand Up @@ -747,6 +750,9 @@ fi
if [ -n "$OVR_TODOTXT_PLAIN" ]; then
TODOTXT_PLAIN="$OVR_TODOTXT_PLAIN"
fi
if [ -n "$OVR_TODOTXT_DATE_FORMAT" ]; then
TODOTXT_DATE_FORMAT="$OVR_TODOTXT_DATE_FORMAT"
fi
if [ -n "$OVR_TODOTXT_DATE_ON_ADD" ]; then
TODOTXT_DATE_ON_ADD="$OVR_TODOTXT_DATE_ON_ADD"
fi
Expand Down Expand Up @@ -818,7 +824,7 @@ _addto()

if [[ "$TODOTXT_DATE_ON_ADD" -eq 1 ]]; then
local now
now=$(date '+%Y-%m-%d')
now=$(date "+$TODOTXT_DATE_FORMAT")
input=$(echo "$input" | sed -e 's/^\(([A-Z]) \)\{0,1\}/\1'"$now /")
fi
if [[ -n "$TODOTXT_PRIORITY_ON_ADD" ]]; then
Expand Down Expand Up @@ -1261,7 +1267,7 @@ case $action in

# Check if this item has already been done
if [ "${todo:0:2}" != "x " ]; then
now=$(date '+%Y-%m-%d')
now=$(date "+$TODOTXT_DATE_FORMAT")
# remove priority once item is done
sed -i.bak "${item}s/^(.) //" "$TODO_FILE"
sed -i.bak "${item}s|^|x $now |" "$TODO_FILE"
Expand Down