Hello.
I made a floor function for time (`dt_floor ()`
). In the example below, 15 minutes, which is 1 hour divided by an integer, is used as the unit of account.
interval = 900 # in seconds
dt = datetime.datetime.strptime("2020-01-01 00:05:05+09:00", '%Y-%m-%d %H:%M:%S%z')
print(dt_floor(dt, interval)) # => "2020-01-01 00:00:00+09:00"
import datetime
MINUTE = 60 # in seconds
HOUR = 3600 # in seconds
ndiv = 4 # in [1, 2, 3, 4, 5, 6, 10, 12, 15, 20, 30, 60]
interval = HOUR//ndiv # in seconds
def dt_floor(dt, interval):
interval_m = interval//MINUTE # in minutes
minute_floor = (dt.minute//interval_m)*interval_m
return dt.replace(minute=minute_floor, second=0)
Recommended Posts