| Michael F. Schönitzer | d93cac1 | 2020-10-05 13:52:58 +0200 | [diff] [blame] | 1 | /* |
| 2 | htop - DateTimeMeter.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 "DateTimeMeter.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 DateTimeMeter_attributes[] = { |
| Michael F. Schönitzer | d93cac1 | 2020-10-05 13:52:58 +0200 | [diff] [blame] | 16 | DATETIME |
| 17 | }; |
| 18 | |
| 19 | static 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öttsche | ba282cf | 2020-10-05 13:19:50 +0200 | [diff] [blame^] | 34 | const MeterClass DateTimeMeter_class = { |
| Michael F. Schönitzer | d93cac1 | 2020-10-05 13:52:58 +0200 | [diff] [blame] | 35 | .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 | }; |