Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- function rounded_time
- param: dt a date time object
- kwarg: rnd the number of minutes to round to
- Since datetime attributes are integers round them like a normal integer
- This function will roll over hours i.e 10:59 -> 11:00
- This function will roll over days i.e 23:59 01/01 -> 00:00 01/02
- """
- from datetime imort datetime, timedelta
- def rounded_time(dt, rnd=15):
- return (
- dt.replace(microsecond=0,
- second=0,
- minute=0,
- hour=dt.hour) +
- timedelta(minutes=int(round(dt.minute/rnd)*rnd))
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement