blob: f3c877b386671e64b276f2653234780f125dcbc8 [file] [log] [blame]
Michael F. Schönitzerd93cac12020-10-05 13:52:58 +02001/*
2htop - DateTimeMeter.c
3(C) 2004-2020 Hisham H. Muhammad, Michael Schönitzer
4Released under the GNU GPL, see the COPYING file
5in the source distribution for its full text.
6*/
7
8#include "DateTimeMeter.h"
9
10#include "CRT.h"
11
12#include <time.h>
13
14
Christian Göttschedc6523b2020-10-05 13:54:33 +020015static const int DateTimeMeter_attributes[] = {
Michael F. Schönitzerd93cac12020-10-05 13:52:58 +020016 DATETIME
17};
18
19static void DateTimeMeter_updateValues(Meter* this, char* buffer, int size) {
20 time_t t = time(NULL);
21 struct tm result;
22 struct tm *lt = localtime_r(&t, &result);
23 int year = lt->tm_year + 1900;
24 if (((year % 4 == 0) && (year % 100!= 0)) || (year%400 == 0)) {
25 this->total = 366;
26 }
27 else {
28 this->total = 365;
29 }
30 this->values[0] = lt->tm_yday;
31 strftime(buffer, size, "%F %H:%M:%S", lt);
32}
33
Christian Göttscheba282cf2020-10-05 13:19:50 +020034const MeterClass DateTimeMeter_class = {
Michael F. Schönitzerd93cac12020-10-05 13:52:58 +020035 .super = {
36 .extends = Class(Meter),
37 .delete = Meter_delete
38 },
39 .updateValues = DateTimeMeter_updateValues,
40 .defaultMode = TEXT_METERMODE,
41 .maxItems = 1,
42 .total = 365,
43 .attributes = DateTimeMeter_attributes,
44 .name = "DateTime",
45 .uiName = "Date and Time",
46 .caption = "Date & Time: ",
47};