Make sure a datetime instance is valid to avoid fatal errors.
Fix types in docblocks.