Python Dates and Times in Python Where on Earth do Timezones Make Sense? Introduction to Timezones

spencer tintorri
spencer tintorri
6,184 Points

For mumbai, is there an advantage to using hours=5, minutes=30 instead of just using hours=5.5 ?

See above. Thank you.

1 Answer

Jeff Muday
MOD
Jeff Muday
Treehouse Moderator 24,879 Points

That is an excellent question-- you are really paying close attention to Kenneth's teaching!

Even though Datetime objects in representation __repr__ are made up of integers rounded to the nearest microsecond (e.g. 10^-9). According to the official documentation, it should not be a problem to use a float for hours.

quote:

All arguments are optional and default to 0. Arguments may be integers or floats, and may be positive or negative.

https://docs.python.org/3/library/datetime.html#:~:text=A%20timedelta%20object%20represents%20a,may%20be%20positive%20or%20negative.

If you are a Python geek like me, you may want to look over the code. There are a number of // (floor division) operators involved in conversions. This means there are quite a bit of floating point operations taking place internally that require conversion back to integers.

https://github.com/python/cpython/blob/3.8/Lib/datetime.py

Good luck with your Python journey!