Developer Journal: 01 May 2020

Posted on Fri 01 May 2020 in dev-journal

While getting things ready for today I used the command to create a new journal entry for the next day dev-journal 1. When doing this on the last day of the month the title for the entry was incorrect. The title generator was echo "Title: Developer Journal: $(date +%d" "%B" "20%y)" >> $filename I'm going to update that and also put the generator within the check for a command line argument. If we need to update the code again later it will be much harder to miss that detail if the logic is grouped together that way.

if [ -z "$1" ]; then
    DATE=$(date +20%y-%m-%d)
    DATE=$(date -d "+$1 days" +20%y-%m-%d)
    TITLEDATE=$(date -d "+$1 days" +%d" "%B" "20%y)

Now the TITLEDATE will generate the formatted date and the title generator now looks like this: echo "Title: Developer Journal: $TITLEDATE" >> $filename

For the future I may use this stackoverflow post to implement some better command-line argument parsing if needed.