Skip to content

Instantly share code, notes, and snippets.

@bazzargh
Last active November 4, 2022 12:09
Show Gist options
  • Save bazzargh/c0f12ef515467cafb605301b3c404912 to your computer and use it in GitHub Desktop.
Save bazzargh/c0f12ef515467cafb605301b3c404912 to your computer and use it in GitHub Desktop.
Misinterpret date formats like General Bison
#!/bin/bash
a=$(( ${1:-$(date +%d)} % 100 ))
b=$(( ${2:-$(date +%m)} % 100 ))
c=$(( ${3:-$(date +%y)} % 100 ))
input=$(printf "%02d-%02d-%02d" "$a" "$b" "$c")
for fmt in "%d-%m-%y" "%d-%y-%m" "%y-%d-%m" "%y-%m-%d" "%m-%y-%d" "%m-%d-%y"; do
if [[ "$(date -j -f "$fmt" "$input" +%u 2>/dev/null || echo 0)" == "2" ]]; then
date -j -f "$fmt" "$input" +"%B %e, %Y? For me, it was Tuesday." 2>/dev/null
exit 0
fi
done
# try harder
for y in {1..99}; do
input=$(printf "%02d %02d-%02d-%02d" "$a" "$b" "$c" "$y")
for fmt in "%H %d-%m-%y" "%H %m-%d-%y"; do
if [[ "$(date -j -f "$fmt" "$input" +%u 2>/dev/null || echo 0)" == "2" ]]; then
date -j -f "$fmt" "$input" +"%I %p %B %e, %Y? For me, it was Tuesday." 2>/dev/null
exit 0
fi
done
done
echo "For you, that day Bison graced your village was the most important day of your life."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment