summaryrefslogtreecommitdiffstats
path: root/DateTimeMeter.c
diff options
context:
space:
mode:
authorMichael F. Schönitzer <michael@schoenitzer.de>2020-10-05 13:52:58 +0200
committerGitHub <noreply@github.com>2020-10-05 13:52:58 +0200
commitd93cac12be1a7a580e338c6fa80286bfa703ffc6 (patch)
tree93d613adc2f698b8bb03c799072c3d4ee8330250 /DateTimeMeter.c
parentffd90c28ab55a2cdbbd5c3b8130e0462a24af8a8 (diff)
Add a date and datetime meter (#159)
Add a date meter and sort header and source files in Makefile Change the lists of header and source files sorted alphabetical and one file per line. This way diffs become better readable and merges easier.
Diffstat (limited to 'DateTimeMeter.c')
-rw-r--r--DateTimeMeter.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/DateTimeMeter.c b/DateTimeMeter.c
new file mode 100644
index 00000000..5c60884a
--- /dev/null
+++ b/DateTimeMeter.c
@@ -0,0 +1,47 @@
+/*
+htop - DateTimeMeter.c
+(C) 2004-2020 Hisham H. Muhammad, Michael Schönitzer
+Released under the GNU GPL, see the COPYING file
+in the source distribution for its full text.
+*/
+
+#include "DateTimeMeter.h"
+
+#include "CRT.h"
+
+#include <time.h>
+
+
+int DateTimeMeter_attributes[] = {
+ DATETIME
+};
+
+static void DateTimeMeter_updateValues(Meter* this, char* buffer, int size) {
+ time_t t = time(NULL);
+ struct tm result;
+ struct tm *lt = localtime_r(&t, &result);
+ int year = lt->tm_year + 1900;
+ if (((year % 4 == 0) && (year % 100!= 0)) || (year%400 == 0)) {
+ this->total = 366;
+ }
+ else {
+ this->total = 365;
+ }
+ this->values[0] = lt->tm_yday;
+ strftime(buffer, size, "%F %H:%M:%S", lt);
+}
+
+MeterClass DateTimeMeter_class = {
+ .super = {
+ .extends = Class(Meter),
+ .delete = Meter_delete
+ },
+ .updateValues = DateTimeMeter_updateValues,
+ .defaultMode = TEXT_METERMODE,
+ .maxItems = 1,
+ .total = 365,
+ .attributes = DateTimeMeter_attributes,
+ .name = "DateTime",
+ .uiName = "Date and Time",
+ .caption = "Date & Time: ",
+};

© 2014-2024 Faster IT GmbH | imprint | privacy policy