From aac35698d1b84f6370d37860c9e889c34cd6a21c Mon Sep 17 00:00:00 2001 From: Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de> Date: Sat, 19 Apr 2008 17:42:20 +0200 Subject: [PATCH] Fixes/enhancements in str?time() functions This patch changes the used format for %x and %X specifiers in strptime(3) to match these specified by SUSv2. It adds support for '%F' in strftime(3) too. --- libugly/strftime.c | 1 + libugly/strptime.c | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/libugly/strftime.c b/libugly/strftime.c index 56ae082..cf16f37 100644 --- a/libugly/strftime.c +++ b/libugly/strftime.c @@ -55,6 +55,7 @@ again: case 'x': src = "%b %a %d"; goto _strf; case 'X': src = "%k:%M:%S"; goto _strf; case 'D': src = "%m/%d/%y"; goto _strf; + case 'F': src = "%Y-%m-%d"; goto _strf; case 'T': src = "%H:%M:%S"; _strf: p += strftime (p, (size_t)(dst+max-p), src, tm); break; case 'a': src = sweekdays [tm->tm_wday]; goto _str; diff --git a/libugly/strptime.c b/libugly/strptime.c index 6ac5340..32dc2a7 100644 --- a/libugly/strptime.c +++ b/libugly/strptime.c @@ -119,10 +119,11 @@ char* strptime(const char* s,const char* format, struct tm* tm) { ++s; break; case 'x': - s=strptime(s,"%b %a %d",tm); + /* see SUSv2, Ch.7 "LC_TIME Category in the POSIX Locale" */ + s=strptime(s,"%m/%d/%y",tm); break; case 'X': - s=strptime(s,"%k:%M:%S",tm); + s=strptime(s,"%H:%M:%S",tm); break; case 'y': i=getint(&s,2); -- 1.5.4.5