Utils.py 1.2 KB

123456789101112131415161718192021222324252627282930
  1. # Copyright (c) 2019 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. from datetime import datetime, timedelta
  4. from UM import i18nCatalog
  5. def formatTimeCompleted(seconds_remaining: int) -> str:
  6. completed = datetime.now() + timedelta(seconds=seconds_remaining)
  7. return "{hour:02d}:{minute:02d}".format(hour = completed.hour, minute = completed.minute)
  8. def formatDateCompleted(seconds_remaining: int) -> str:
  9. now = datetime.now()
  10. completed = now + timedelta(seconds=seconds_remaining)
  11. days = (completed.date() - now.date()).days
  12. i18n = i18nCatalog("cura")
  13. # If finishing date is more than 7 days out, using "Mon Dec 3 at HH:MM" format
  14. if days >= 7:
  15. return completed.strftime("%a %b ") + "{day}".format(day = completed.day)
  16. # If finishing date is within the next week, use "Monday at HH:MM" format
  17. elif days >= 2:
  18. return completed.strftime("%a")
  19. # If finishing tomorrow, use "tomorrow at HH:MM" format
  20. elif days >= 1:
  21. return i18n.i18nc("@info:status", "tomorrow")
  22. # If finishing today, use "today at HH:MM" format
  23. else:
  24. return i18n.i18nc("@info:status", "today")