]> granicus.if.org Git - vnstat/commitdiff
define one common datetime format in common.h
authorTeemu Toivola <git@humdi.net>
Sun, 18 Mar 2018 17:56:51 +0000 (19:56 +0200)
committerTeemu Toivola <git@humdi.net>
Sun, 18 Mar 2018 17:56:51 +0000 (19:56 +0200)
src/common.c
src/common.h
src/daemon.c
src/dbshow.c

index e090e626a26e122766abf47fe86bdcffedcbd598..88ed0c376fea4bdfcb80517675b1cd03514242aa 100644 (file)
@@ -87,7 +87,7 @@ int logprint(PrintType type)
                }
 
                current = time(NULL);
-               strftime(timestamp, 22, "%Y-%m-%d %H:%M:%S", localtime(&current));
+               strftime(timestamp, 22, DATETIMEFORMAT, localtime(&current));
 
                switch (type) {
                        case PT_Info:
index 3ecd019c5aec1b837fd077a98cc28e64320b6055..797a094a9628b2680e64dba6d60ba9c3e3fd36ab 100644 (file)
@@ -80,6 +80,10 @@ and most can be changed later from the config file.
 #define TFORMAT "%Y-%m-%d"             /* "%x"         "%d.%m.%y" */
 #define HFORMAT "%Y-%m-%d %H:%M"       /* "%x %H:%M"   "%d.%m.%Y %H:%M" */
 
+#ifndef DATETIMEFORMAT
+#define DATETIMEFORMAT "%Y-%m-%d %H:%M:%S"
+#endif
+
 /* characters used for visuals */
 #define RXCHAR "%"
 #define TXCHAR ":"
index ea032ed957cc0a13f596611152b10fdd99d15eda..96d3d55fceed298117f1b5b2eaa429a4be5e28a9 100644 (file)
@@ -234,7 +234,7 @@ void debugtimestamp(void)
        char timestamp[22];
 
        now = time(NULL);
-       strftime(timestamp, 22, "%Y-%m-%d %H:%M:%S", localtime(&now));
+       strftime(timestamp, 22, DATETIMEFORMAT, localtime(&now));
        printf("%s\n", timestamp);
 }
 
@@ -982,7 +982,7 @@ int waittimesync(DSTATE *s)
                        }
 
                        if (debug) {
-                               strftime(timestamp, 22, "%Y-%m-%d %H:%M:%S", localtime(&iterator->updated));
+                               strftime(timestamp, 22, DATETIMEFORMAT, localtime(&iterator->updated));
                                printf("w: has %s\n", timestamp);
                        }
                        if (iterator->updated > s->prevdbsave) {
@@ -1000,31 +1000,31 @@ int waittimesync(DSTATE *s)
        s->current = time(NULL);
 
        if (debug) {
-               strftime(timestamp, 22, "%Y-%m-%d %H:%M:%S", localtime(&s->current));
+               strftime(timestamp, 22, DATETIMEFORMAT, localtime(&s->current));
                printf("current time:     %s\n", timestamp);
-               strftime(timestamp2, 22, "%Y-%m-%d %H:%M:%S", localtime(&s->prevdbsave));
+               strftime(timestamp2, 22, DATETIMEFORMAT, localtime(&s->prevdbsave));
                printf("latest db update: %s\n", timestamp2);
        }
 
        if (s->current < s->prevdbsave) {
                if (s->prevdbupdate == 0) {
                        s->prevdbupdate = s->current;
-                       strftime(timestamp, 22, "%Y-%m-%d %H:%M:%S", localtime(&s->current));
-                       strftime(timestamp2, 22, "%Y-%m-%d %H:%M:%S", localtime(&s->prevdbsave));
+                       strftime(timestamp, 22, DATETIMEFORMAT, localtime(&s->current));
+                       strftime(timestamp2, 22, DATETIMEFORMAT, localtime(&s->prevdbsave));
                        snprintf(errorstring, 1024, "Latest database update is in the future (db: %s > now: %s). Giving the system clock up to %d minutes to sync before continuing.", timestamp2, timestamp, cfg.timesyncwait);
                        printe(PT_Info);
                }
                if (s->current - s->prevdbupdate >= cfg.timesyncwait*60) {
-                       strftime(timestamp, 22, "%Y-%m-%d %H:%M:%S", localtime(&s->current));
-                       strftime(timestamp2, 22, "%Y-%m-%d %H:%M:%S", localtime(&s->prevdbsave));
+                       strftime(timestamp, 22, DATETIMEFORMAT, localtime(&s->current));
+                       strftime(timestamp2, 22, DATETIMEFORMAT, localtime(&s->prevdbsave));
                        snprintf(errorstring, 1024, "Latest database update is still in the future (db: %s > now: %s), continuing. Some errors may follow.", timestamp2, timestamp);
                        printe(PT_Info);
                        return 0;
                }
        } else {
                if (s->prevdbupdate != 0) {
-                       strftime(timestamp, 22, "%Y-%m-%d %H:%M:%S", localtime(&s->current));
-                       strftime(timestamp2, 22, "%Y-%m-%d %H:%M:%S", localtime(&s->prevdbsave));
+                       strftime(timestamp, 22, DATETIMEFORMAT, localtime(&s->current));
+                       strftime(timestamp2, 22, DATETIMEFORMAT, localtime(&s->prevdbsave));
                        snprintf(errorstring, 1024, "Latest database update is no longer in the future (db: %s <= now: %s), continuing.", timestamp2, timestamp);
                        printe(PT_Info);
                }
index 36c827b70c80e3fe75acb9008fb2475ec6b8a563..97e90417fc4d9b84980dc6d9feb9d4a3b4c700c8 100644 (file)
@@ -79,7 +79,7 @@ void showsummary(const interfaceinfo *interface, const int shortmode)
        e_rx=e_tx=0;
 
        if (interface->updated && !shortmode) {
-               strftime(datebuff, DATEBUFFLEN, "%Y-%m-%d %H:%M:%S", localtime(&interface->updated));
+               strftime(datebuff, DATEBUFFLEN, DATETIMEFORMAT, localtime(&interface->updated));
                printf("Database updated: %s\n\n", datebuff);
        } else if (!shortmode) {
                printf("\n");