From 092b5ae0cede6bbeb2d5ed3bad12b775a7b86baa Mon Sep 17 00:00:00 2001 From: Miles Bader Date: Tue, 23 Jul 1996 04:10:04 +0000 Subject: (fmt_past_time): Try several separators when concatenating dates & times. --- libshouldbeinlibc/timefmt.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/libshouldbeinlibc/timefmt.c b/libshouldbeinlibc/timefmt.c index aab71c59..19a6a03a 100644 --- a/libshouldbeinlibc/timefmt.c +++ b/libshouldbeinlibc/timefmt.c @@ -282,7 +282,7 @@ fmt_past_time (struct timeval *tv, struct timeval *now, size_t width, char *buf, size_t buf_len) { static char *time_fmts[] = { "%-r", "%-l:%M%p", "%-l%p", 0 }; - static char *week_fmts[] = { "%A,", "%a,", "%a", 0 }; + static char *week_fmts[] = { "%A", "%a", 0 }; static char *month_fmts[] = { "%A, %-d", "%a, %-d", "%a %-d", "%a%-d", 0 }; static char *date_fmts[] = { "%A, %-d %B", "%a, %-d %b", "%-d %B", "%-d %b", "%-d%b", 0 }; @@ -313,7 +313,8 @@ fmt_past_time (struct timeval *tv, struct timeval *now, } else { - char **fmt, **dfmt, **dfmts; + static char *seps[] = { ", ", " ", "" }; + char **fmt, **dfmt, **dfmts, **sep; if (diff < WEEK) dfmts = week_fmts; @@ -324,20 +325,22 @@ fmt_past_time (struct timeval *tv, struct timeval *now, else dfmts = year_fmts; + /* This ordering (date varying most quickly, then the separator, then + the time) preserves time detail as long as possible, and seems to + produce a graceful degradation of the result with decreasing widths. */ for (fmt = time_fmts; *fmt && !used; fmt++) - { + for (sep = seps; *sep && !used; sep++) for (dfmt = dfmts; *dfmt && !used; dfmt++) { - char whole_fmt[strlen (*dfmt) + 1 + strlen (*fmt) + 1]; + char whole_fmt[strlen (*dfmt) + strlen (*sep) + strlen (*fmt) + 1]; char *end = whole_fmt; end = stpcpy (end, *dfmt); - *end++ = ' '; + end = stpcpy (end, *sep); end = stpcpy (end, *fmt); used = strftime (buf, width, whole_fmt, &tm); } - } if (! used) /* No concatenated formats worked, try just date formats. */ -- cgit v1.2.3