Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

duration.py 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import datetime
  2. def _get_duration_components(duration):
  3. days = duration.days
  4. seconds = duration.seconds
  5. microseconds = duration.microseconds
  6. minutes = seconds // 60
  7. seconds = seconds % 60
  8. hours = minutes // 60
  9. minutes = minutes % 60
  10. return days, hours, minutes, seconds, microseconds
  11. def duration_string(duration):
  12. """Version of str(timedelta) which is not English specific."""
  13. days, hours, minutes, seconds, microseconds = _get_duration_components(duration)
  14. string = "{:02d}:{:02d}:{:02d}".format(hours, minutes, seconds)
  15. if days:
  16. string = "{} ".format(days) + string
  17. if microseconds:
  18. string += ".{:06d}".format(microseconds)
  19. return string
  20. def duration_iso_string(duration):
  21. if duration < datetime.timedelta(0):
  22. sign = "-"
  23. duration *= -1
  24. else:
  25. sign = ""
  26. days, hours, minutes, seconds, microseconds = _get_duration_components(duration)
  27. ms = ".{:06d}".format(microseconds) if microseconds else ""
  28. return "{}P{}DT{:02d}H{:02d}M{:02d}{}S".format(
  29. sign, days, hours, minutes, seconds, ms
  30. )
  31. def duration_microseconds(delta):
  32. return (24 * 60 * 60 * delta.days + delta.seconds) * 1000000 + delta.microseconds