DateMeter.c 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. htop - DateMeter.c
  3. (C) 2004-2020 Hisham H. Muhammad, Michael Schönitzer
  4. Released under the GNU GPLv2+, see the COPYING file
  5. in the source distribution for its full text.
  6. */
  7. #include "config.h" // IWYU pragma: keep
  8. #include "DateMeter.h"
  9. #include <time.h>
  10. #include <sys/time.h>
  11. #include "CRT.h"
  12. #include "Machine.h"
  13. #include "Object.h"
  14. static const int DateMeter_attributes[] = {
  15. DATE
  16. };
  17. static void DateMeter_updateValues(Meter* this) {
  18. const Machine* host = this->host;
  19. struct tm result;
  20. const struct tm* lt = localtime_r(&host->realtime.tv_sec, &result);
  21. strftime(this->txtBuffer, sizeof(this->txtBuffer), "%F", lt);
  22. }
  23. const MeterClass DateMeter_class = {
  24. .super = {
  25. .extends = Class(Meter),
  26. .delete = Meter_delete
  27. },
  28. .updateValues = DateMeter_updateValues,
  29. .defaultMode = TEXT_METERMODE,
  30. .supportedModes = (1 << TEXT_METERMODE) | (1 << LED_METERMODE),
  31. .maxItems = 0,
  32. .total = 0.0,
  33. .attributes = DateMeter_attributes,
  34. .name = "Date",
  35. .uiName = "Date",
  36. .caption = "Date: ",
  37. };