diff --git a/libmisc/date_to_str.c b/libmisc/date_to_str.c index f3b9dc76..67b99317 100644 --- a/libmisc/date_to_str.c +++ b/libmisc/date_to_str.c @@ -33,15 +33,24 @@ #include "prototypes.h" -void date_to_str (size_t size, char buf[size], long date) +void +date_to_str(size_t size, char buf[size], long date) { - time_t t; + time_t t; + const struct tm *tm; t = date; if (date < 0) { - (void) strlcpy (buf, "never", size); - } else { - (void) strftime (buf, size, "%Y-%m-%d", gmtime (&t)); - buf[size - 1] = '\0'; + (void) strlcpy(buf, "never", size); + return; } + + tm = gmtime(&t); + if (tm == NULL) { + (void) strlcpy(buf, "future", size); + return; + } + + (void) strftime(buf, size, "%Y-%m-%d", tm); + buf[size - 1] = '\0'; }