def difft(start, end):
    a, b, c, d = start.hour, start.minute, start.second, start.microsecond
w, x, y, z = end.hour, end.minute, end.second, end.microsecond
delt = (w - a) * 60 + (x - b) + (y - c) / 60.0 + (z - d) / 60000000
D = '%sh %smn %ss %sms - %sh %smn %ss %sms == '
ft = '%s + 1440 = %s  (1440 = 24x60mn)'
return D % (w, x, y, z, a, b, c, d) + (ft % (delt, delt + 1440) if delt < 0
     else str(delt))
print(difft(time(11, 30, 0), time(12, 35, 0)))
print(difft(time(11, 30, 0), time(10, 35, 0)))
print() 
print(difft(time(20, 40, 0), time(22, 41, 0)))
print(difft(time(20, 40, 0), time(18, 41, 0)))
how to substract two datetime.time values in django template,and how to format a duration as hour,minutes