blob: c2aa7ea18ceea8a3d7a5c2595ec7572f18b9c480 [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
Benny Baumann0f526292020-09-19 13:55:23 +02008#include "config.h" // IWYU pragma: keep
9
Michael F. Schönitzerd93cac12020-10-05 13:52:58 +020010#include "DateMeter.h"
11
Michael F. Schönitzerd93cac12020-10-05 13:52:58 +020012#include <time.h>
13
Benny Baumann0f526292020-09-19 13:55:23 +020014#include "CRT.h"
15#include "Object.h"
16
Michael F. Schönitzerd93cac12020-10-05 13:52:58 +020017
Christian Göttschedc6523b2020-10-05 13:54:33 +020018static const int DateMeter_attributes[] = {
Michael F. Schönitzerd93cac12020-10-05 13:52:58 +020019 DATE
20};
21
Christian Göttschee1ce1412020-11-24 18:31:03 +010022static void DateMeter_updateValues(Meter* this, char* buffer, size_t size) {
Michael F. Schönitzerd93cac12020-10-05 13:52:58 +020023 time_t t = time(NULL);
24 struct tm result;
Christian Göttsched72b0a62021-01-05 23:42:55 +010025 const struct tm* lt = localtime_r(&t, &result);
Michael F. Schönitzerd93cac12020-10-05 13:52:58 +020026 this->values[0] = lt->tm_yday;
27 int year = lt->tm_year + 1900;
Benny Baumann61e14d42020-10-31 23:28:02 +010028 if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) {
Michael F. Schönitzerd93cac12020-10-05 13:52:58 +020029 this->total = 366;
Christian Göttsche635d4cf2021-02-28 22:47:45 +010030 } else {
Michael F. Schönitzerd93cac12020-10-05 13:52:58 +020031 this->total = 365;
32 }
33 strftime(buffer, size, "%F", lt);
34}
35
Christian Göttscheba282cf2020-10-05 13:19:50 +020036const MeterClass DateMeter_class = {
Michael F. Schönitzerd93cac12020-10-05 13:52:58 +020037 .super = {
38 .extends = Class(Meter),
39 .delete = Meter_delete
40 },
41 .updateValues = DateMeter_updateValues,
42 .defaultMode = TEXT_METERMODE,
43 .maxItems = 1,
44 .total = 365,
45 .attributes = DateMeter_attributes,
46 .name = "Date",
47 .uiName = "Date",
48 .caption = "Date: ",
49};