Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. """
  2. function rounded_time
  3. param: dt a date time object
  4. kwarg: rnd the number of minutes to round to
  5.  
  6. Since datetime attributes are integers round them like a normal integer
  7. This function will roll over hours i.e 10:59 -> 11:00
  8. This function will roll over days i.e 23:59 01/01 -> 00:00 01/02
  9. """
  10. from datetime imort datetime, timedelta
  11.  
  12. def rounded_time(dt, rnd=15):
  13. return (
  14. dt.replace(microsecond=0,
  15. second=0,
  16. minute=0,
  17. hour=dt.hour) +
  18. timedelta(minutes=int(round(dt.minute/rnd)*rnd))
  19. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement