Guest User

Untitled

a guest
Jun 25th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. def express_as_duration(delta)
  2. timestamp = []
  3. hours = int(delta / (60 * 60))
  4. minutes = int((delta % (60 * 60)) / 60)
  5. seconds = delta % 60
  6.  
  7. if hours > 0:
  8. if hours == 1:
  9. timestamp.append("1 hour")
  10. else:
  11. timestamp.append("{} hours".format(hours))
  12. if minutes > 0:
  13. if minutes == 1:
  14. timestamp.append("1 minute")
  15. else:
  16. timestamp.append("{} minutes".format(minutes))
  17. timestamp.append("{0:.2f} seconds".format(seconds))
  18. return ', '.join(timestamp)
Add Comment
Please, Sign In to add comment