Fix for TypeError: can't compare datetime to bool