def delta_resolution(dt, delta):
 delta = timedelta_seconds(delta)
 resolutions = ((3, (lambda x: (x / 86400))), (4, (lambda x: (x / 3600))), (5, (lambda x: (x / 60))))
 args = (dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second)
 for (res, predicate) in resolutions:
  if (predicate(delta) >= 1.0):
   return datetime(*args[:res])
 return dt

def delta_resolution ( dt , delta ) : delta = timedelta_seconds ( delta ) resolutions = ( ( 3 , ( lambda x : ( x / 86400 ) ) ) , ( 4 , ( lambda x : ( x / 3600 ) ) ) , ( 5 , ( lambda x : ( x / 60 ) ) ) ) args = ( dt . year , dt . month , dt . day , dt . hour , dt . minute , dt . second ) for ( res , predicate ) in resolutions : if ( predicate ( delta ) >= 1.0 ) : return datetime ( * args [ : res ] ) return dt
round a datetime to the resolution of a timedelta .