From a85d49580e2c1251d7ea9eebad672f802d82ec40 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Tue, 2 Dec 2014 16:32:56 +0000 Subject: date: add support for %s format --- win32/mingw.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/win32/mingw.c b/win32/mingw.c index eeafd7d75..8a124147a 100644 --- a/win32/mingw.c +++ b/win32/mingw.c @@ -837,11 +837,14 @@ size_t mingw_strftime(char *buf, size_t max, const char *format, const struct tm size_t ret; char day[3]; char *t; - char *fmt; + char *fmt, *newfmt; + struct tm tm2; + int m; /* - * Emulate the '%e' format that Windows' strftime lacks. Happily, the - * string that replaces '%e' is always two characters long. + * Emulate the '%e' and '%s' formats that Windows' strftime lacks. + * Happily, the string that replaces '%e' is two characters long. + * '%s' is a bit more complicated. */ fmt = xstrdup(format); for ( t=fmt; *t; ++t ) { @@ -855,6 +858,15 @@ size_t mingw_strftime(char *buf, size_t max, const char *format, const struct tm } memcpy(t++, day, 2); } + else if ( t[1] == 's' ) { + *t = '\0'; + m = t - fmt; + tm2 = *tm; + newfmt = xasprintf("%s%d%s", fmt, (int)mktime(&tm2), t+2); + free(fmt); + t = newfmt + m + 1; + fmt = newfmt; + } else if ( t[1] != '\0' ) { ++t; } -- cgit v1.2.3-55-g6feb