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.

29 lines
894 B

  1. """Functions to work with dates and times in a uniform way.
  2. The results of these functions are cached for 5 seconds to provide uniform time strings across short running processes. Long running processes that need more precise timekeeping should not use these functions.
  3. """
  4. from time import gmtime, strftime
  5. from qmk.constants import DATE_FORMAT, DATETIME_FORMAT, TIME_FORMAT
  6. from qmk.decorators import lru_cache
  7. @lru_cache(timeout=5)
  8. def current_date():
  9. """Returns the current time in UTZ as a formatted string.
  10. """
  11. return strftime(DATE_FORMAT, gmtime())
  12. @lru_cache(timeout=5)
  13. def current_datetime():
  14. """Returns the current time in UTZ as a formatted string.
  15. """
  16. return strftime(DATETIME_FORMAT, gmtime())
  17. @lru_cache(timeout=5)
  18. def current_time():
  19. """Returns the current time in UTZ as a formatted string.
  20. """
  21. return strftime(TIME_FORMAT, gmtime())