Bug fixes and improvements for datetime.py