Last active
July 31, 2020 22:08
-
-
Save JFFail/dee8f161b4bd3ed7a842 to your computer and use it in GitHub Desktop.
Solution to Reddit Daily Programmer 201
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/pkg/bin/zsh | |
dateMath() { | |
todayMonth=$(date "+%m/%d/%y" | awk -F\/ '{print $1}' | sed "s/^0//") | |
todayDay=$(date "+%m/%d/%y" | awk -F\/ '{print $2}' | sed "s/^0//") | |
todayYear=$(date "+%m/%d/%y" | awk -F\/ '{print $3}' | sed "s/^0//") | |
today="$todayMonth/$todayDay/$todayYear" | |
current=$(date -d $today +%s) | |
submitted=$(date -d $1 +%s) | |
diffDays=$((($submitted - $current) / 86400)) | |
echo "You must wait $diffDays days from $today to $1" | |
} | |
input="2016 2 9" | |
year=$(echo $input | awk '{print $1}') | |
month=$(echo $input | awk '{print $2}') | |
day=$(echo $input | awk '{print $3}') | |
inputDate="$month/$day/$year" | |
dateMath $inputDate |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment