The code is from this page:
https://github.com/reddit/reddit/blob/master/r2/r2/lib/db/_sorts.pyx
Here is the code snippet:
cpdef double epoch_seconds(date):
"""Returns the number of seconds from the epoch to date. Should
match the number returned by the equivalent function in
postgres."""
td = date - epoch
return td.days * 86400 + td.seconds + (float(td.microseconds) / 1000000)
I think td.days * 86400 should be equal to td.seconds as well as (float(td.microseconds) / 1000000), I was wondering why didn’t they simply make td.seconds multiply 3?
Your assumptions are wrong and that is why this seams weird.
td.dayscontains the number of days since the epoch as you correctly assumed, buttd.secondsandtd.microsecondscontains the number of seconds since the start of the day and the number of microseconds since the start of the second respectively. Thus the return value becomes the number of seconds since the epoch with microseconds as the part after the comma.