blob: 224de306ca5f127f6444543546daa77f49bf0b5f [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
Daniel Lange94ad1112021-09-22 11:33:00 +02004Released under the GNU GPLv2+, see the COPYING file
Michael F. Schönitzerd93cac12020-10-05 13:52:58 +02005in 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>
mayurdahibhate1b74dfe2021-04-29 20:42:43 +053013#include <sys/time.h>
Michael F. Schönitzerd93cac12020-10-05 13:52:58 +020014
Benny Baumann0f526292020-09-19 13:55:23 +020015#include "CRT.h"
16#include "Object.h"
Nathan Scottb74673f2023-08-31 11:56:43 +100017#include "ProcessTable.h"
Benny Baumann0f526292020-09-19 13:55:23 +020018
Michael F. Schönitzerd93cac12020-10-05 13:52:58 +020019
Christian Göttschedc6523b2020-10-05 13:54:33 +020020static const int DateMeter_attributes[] = {
Michael F. Schönitzerd93cac12020-10-05 13:52:58 +020021 DATE
22};
23
Christian Göttsche2d1042a2020-10-06 13:13:16 +020024static void DateMeter_updateValues(Meter* this) {
Nathan Scott0bdade12023-05-02 09:02:22 +100025 const Machine* host = this->host;
Sohaib421bdee2021-03-23 08:27:05 +020026
Michael F. Schönitzerd93cac12020-10-05 13:52:58 +020027 struct tm result;
Nathan Scott0bdade12023-05-02 09:02:22 +100028 const struct tm* lt = localtime_r(&host->realtime.tv_sec, &result);
Michael F. Schönitzerd93cac12020-10-05 13:52:58 +020029 this->values[0] = lt->tm_yday;
30 int year = lt->tm_year + 1900;
Benny Baumann61e14d42020-10-31 23:28:02 +010031 if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) {
Michael F. Schönitzerd93cac12020-10-05 13:52:58 +020032 this->total = 366;
Christian Göttsche635d4cf2021-02-28 22:47:45 +010033 } else {
Michael F. Schönitzerd93cac12020-10-05 13:52:58 +020034 this->total = 365;
35 }
Christian Göttsche2d1042a2020-10-06 13:13:16 +020036 strftime(this->txtBuffer, sizeof(this->txtBuffer), "%F", lt);
Michael F. Schönitzerd93cac12020-10-05 13:52:58 +020037}
38
Christian Göttscheba282cf2020-10-05 13:19:50 +020039const MeterClass DateMeter_class = {
Michael F. Schönitzerd93cac12020-10-05 13:52:58 +020040 .super = {
41 .extends = Class(Meter),
42 .delete = Meter_delete
43 },
44 .updateValues = DateMeter_updateValues,
45 .defaultMode = TEXT_METERMODE,
46 .maxItems = 1,
47 .total = 365,
48 .attributes = DateMeter_attributes,
49 .name = "Date",
50 .uiName = "Date",
51 .caption = "Date: ",
52};