#!/usr/bin/env bash

DATE=$1
declare -i day

if [[ ${#DATE} -ne 10 ]] ; then
   echo ""
   echo "Invalid Date: $DATE"
   echo ""
   echo -e "Usage: \033[1m$(basename $0) YYYYMMDD\033[m"
   echo ""
   exit 0
fi

eval $(echo $DATE | sed 's/^\(....\)\(..\)\(..\)/year=\1 month=\2 day=\3/')

cal $month $year 2> /dev/null | grep -w $day > /dev/null
if [[ $? -eq 0 ]] ; then
   echo ""
   echo "Valid Date: $DATE"
   echo ""
else
   echo ""
   echo "Invalid Date: $DATE"
   echo ""
   echo "Usage: $(basename $0) YYYYMMDD"
   echo ""
fi

exit 0
