def truncate_second(dt, measure):
 d = datetime(dt.year, dt.month, dt.day, tzinfo=dt.tzinfo)
 seconds = ((total_seconds((dt - d)) // measure) * measure)
 return dt.utcfromtimestamp((seconds + utctotimestamp(d)))

def truncate_second ( dt , measure ) : d = datetime ( dt . year , dt . month , dt . day , tzinfo = dt . tzinfo ) seconds = ( ( total_seconds ( ( dt - d ) ) // measure ) * measure ) return dt . utcfromtimestamp ( ( seconds + utctotimestamp ( d ) ) )
truncate by second .