| Michael F. Schönitzer | d93cac1 | 2020-10-05 13:52:58 +0200 | [diff] [blame] | 1 | /* |
| 2 | htop - DateMeter.c |
| 3 | (C) 2004-2020 Hisham H. Muhammad, Michael Schönitzer |
| 4 | Released under the GNU GPL, see the COPYING file |
| 5 | in 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öttsche | dc6523b | 2020-10-05 13:54:33 +0200 | [diff] [blame^] | 15 | static const int DateMeter_attributes[] = { |
| Michael F. Schönitzer | d93cac1 | 2020-10-05 13:52:58 +0200 | [diff] [blame] | 16 | DATE |
| 17 | }; |
| 18 | |
| 19 | static 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 | |
| 34 | MeterClass 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 | }; |