I am first taking an epoch timestamp and converting it to a UTC dt using:
d = datetime.utcfromtimestamp(input_epoch)
Using the following SO post: How can I get hours from a Python datetime?, i am then grabbing the hour:
h = d.hour + d.minute / 60. + d.second / 3600
But this maps an epoch that translates to whatever-10:59:59AM to 10AM. I want a function that will map a given epoch to the closest hour using rounding, e.g., hour:00:00-> hour:00:30:00 -> hour, hour:30:01-> hour:59:59 -> hour+1.
My current best idea is to do:
d = datetime.utcfromtimestamp(input_epoch+3600/2)
But I am not convinced this is correct. Is there another builtin library function that will do this more rigorously?