diff options
Diffstat (limited to 'src/status/datetime.c')
-rw-r--r-- | src/status/datetime.c | 61 |
1 files changed, 39 insertions, 22 deletions
diff --git a/src/status/datetime.c b/src/status/datetime.c index a25d411..d7d9d0a 100644 --- a/src/status/datetime.c +++ b/src/status/datetime.c @@ -1,36 +1,53 @@ #include <stdio.h> #include <time.h> -#include "status/datetime.h" +#include "common.h" #include "config.h" -void status_datetime() +void status_datetime(GlobalData *g) { + StatusItem s; + char text[32] = { 0 }; + time_t nows = 0; struct tm *nowtm; + + statusitem_init(&s); + s.text = text; + nows = time(NULL); if (nows == ((time_t) -1)) { - printf(" ^fg(red)ERROR: DATETIME"); - return; - } + s.color = "red"; + s.text = "ERROR: DATETIME"; - nowtm = localtime(&nows); - - printf(" ^fg(#666666)%d.%d.%d ^fg(grey)%d:%.2d" - #ifdef SHOW_SECONDS - ":%.2d" - #endif - " " - ,nowtm -> tm_mday, - (nowtm -> tm_mon) + 1, - (nowtm -> tm_year) + 1900, - nowtm -> tm_hour, - nowtm -> tm_min - - #ifdef SHOW_SECONDS - ,nowtm -> tm_sec - #endif - ); + line_append_item(g, &s); + } else { + nowtm = localtime(&nows); + + s.color = "#666666"; + snprintf(text, sizeof(text), + "%d.%d.%d", + nowtm->tm_mday, + (nowtm->tm_mon) + 1, + (nowtm->tm_year) + 1900 + ); + line_append_item(g, &s); + + s.color = "grey"; + snprintf(text, sizeof(text), + "%d:%.2d" + #ifdef SHOW_SECONDS + ":%.2d" + #endif + ,nowtm->tm_hour, + nowtm->tm_min + + #ifdef SHOW_SECONDS + ,nowtm -> tm_sec + #endif + ); + line_append_item(g, &s); + } } |