abcc07b59d773344f138eeea3fbe53d2445903cb
[sysstatus.git] / statuses / datetime.c
1 #include <stdio.h>
2 #include <time.h>
3 #include "datetime.h"
4 #include "../config.h"
5
6 void status_datetime()
7 {
8   time_t nows = 0;
9   struct tm *nowtm;
10
11   nows = time(NULL);
12   if (nows == ((time_t) -1)) {
13     printf(" ^fg(red)ERROR: DATETIME");
14     return;
15   }
16
17   nowtm = localtime(&nows);
18
19   printf(" ^fg(#666666)%d.%d.%d  ^fg(grey)%d:%.2d"
20         #ifdef SHOW_SECONDS
21         ":%.2d"
22         #endif
23         " "
24         ,nowtm -> tm_mday,
25         (nowtm -> tm_mon) + 1,
26         (nowtm -> tm_year) + 1900,
27         nowtm -> tm_hour,
28         nowtm -> tm_min
29
30         #ifdef SHOW_SECONDS
31         ,nowtm -> tm_sec
32         #endif
33     );
34 }