It seems that checking if it's xx:00:00 UTC/GMT is as simple as checking if timestamp % 3600 == 0
, with timestamp = number of seconds elapsed since epoch (1970-01-01 00:00:00). We can see it here:
import datetime
print datetime.datetime.fromtimestamp(3600*24*17000)
# 2016-07-18 02:00:00
But isn't this in contradiction with leap seconds? Indeed, the number of seconds elapsed between 1970-01-01 00:00:00 and 2016-07-18 02:00:00 is not a multiple of 3600, but a multiple of 3600 + 26 leap seconds (there have been 26 leap seconds between 1972 and now).
To be more precise: the number of elapsed seconds between 1970-01-01 00:00:00 and 2016-07-18 02:00:00 is 3600*24*17000 + 26
and not 3600*24*17000
.
Python's
datetime.datetime
objects can not handle leap seconds since theseconds
attribute is limited to the range 0..59:(There was a leap second just before midnight, 2012-06-30).
So Python's datetime system does not quite represent all times as they exist in the real world. It models a simplified world where no leap seconds exist.
See also: this python issue which was closed with status "won't fix".
The linked page shows
mxDatetime
as an alternative todatetime.datetime
which can (sort of) handle leap seconds.