blob: e130159ade2d8aa301d549414398c01eab43d6eb [file] [log] [blame]
Michael F. Schönitzerd93cac12020-10-05 13:52:58 +02001/*
2htop - DateMeter.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 "DateMeter.h"
9
10#include "CRT.h"
11
12#include <time.h>
13
14
Christian Göttschedc6523b2020-10-05 13:54:33 +020015static const int DateMeter_attributes[] = {
Michael F. Schönitzerd93cac12020-10-05 13:52:58 +020016 DATE
17};
18
19static void DateMeter_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 this->values[0] = lt->tm_yday;
24 int year = lt->tm_year + 1900;
25 if (((year % 4 == 0) && (year % 100!= 0)) || (year%400 == 0)) {
26 this->total = 366;
27 }
28 else {
29 this->total = 365;
30 }
31 strftime(buffer, size, "%F", lt);
32}
33
34MeterClass DateMeter_class = {
35 .super = {
36 .extends = Class(Meter),
37 .delete = Meter_delete
38 },
39 .updateValues = DateMeter_updateValues,
40 .defaultMode = TEXT_METERMODE,
41 .maxItems = 1,
42 .total = 365,
43 .attributes = DateMeter_attributes,
44 .name = "Date",
45 .uiName = "Date",
46 .caption = "Date: ",
47};