In other words, a normal year has 365 days while a Leap Year has 366 days (the extra day is the 29th of February).
Having been discussing with a few scientists about datetime handling in programming language, we do have a question if the concept of leap year and second is really applied to common programming languages, especially Python. I have been satisfied with Python's strength and capability, just not so sure about how well it deals with the calendar issue like leap year and second. To illustrate whether Python can handle leap year correctly, here's the examples:
In [2]: import datetime In [3]: datetime.datetime(2011, 2, 28) + datetime.timedelta(days=10) Out[3]: datetime.datetime(2011, 3, 10, 0, 0) In [4]: datetime.datetime(2011, 2, 28) + datetime.timedelta(days=1) Out[4]: datetime.datetime(2011, 3, 1, 0, 0) In [5]: datetime.datetime(2012, 2, 28) + datetime.timedelta(days=1) Out[5]: datetime.datetime(2012, 2, 29, 0, 0)As a highlight, there were only 28 days in February in 2011 while there were 29 days in February in 2012. Sounds good.
So how about datetime object itself?
According to Python library manual, a datetime object is a single object containing all the information from a date object and a time object. Like a date object, datetime assumes the current Gregorian calendar extended in both directions; like a time object, datetime assumes there are exactly 3600*24 seconds in every day.
Okay, so what about Leap Seconds?
According to a post in September 2016 on Stackoverflow, leap seconds are occasionally manually scheduled. Currently, computer clocks have no facility to honour leap seconds; there is no standard to tell them up-front to insert one. Instead, computer clocks periodically re-synch their time keeping via the NTP protocol and adjust automatically after the leap second has been inserted.
Next, computer clocks usually report the time as seconds since the epoch. It'd be up to the datetime module to adjust its accounting when converting that second count to include leap seconds. It doesn't do this at present. time.time() will just report a time count based on the seconds-since-the-epoch.
So, nothing different will happen when the leap second is officially in effect, other than that your computer clock will be 1 second of for a little while.
The issues with datetime only cover representing a leap second timestamp, which it can't. It won't be asked to do so anyway.
Rest assured that Python handled leap year well in the past and hopefully will do it good enough for the ongoing future.
In [6]: datetime.datetime(2049, 2, 28) + datetime.timedelta(days=1) Out[6]: datetime.datetime(2049, 3, 1, 0, 0) In [7]: datetime.datetime(2050, 2, 28) + datetime.timedelta(days=1) Out[7]: datetime.datetime(2050, 3, 1, 0, 0) In [8]: datetime.datetime(2051, 2, 28) + datetime.timedelta(days=1) Out[8]: datetime.datetime(2051, 3, 1, 0, 0) In [9]: datetime.datetime(2052, 2, 28) + datetime.timedelta(days=1) Out[9]: datetime.datetime(2052, 2, 29, 0, 0)