diff options
author | Miles Bader <miles@gnu.org> | 1996-07-23 04:10:04 +0000 |
---|---|---|
committer | Miles Bader <miles@gnu.org> | 1996-07-23 04:10:04 +0000 |
commit | 092b5ae0cede6bbeb2d5ed3bad12b775a7b86baa (patch) | |
tree | 2026e39ebd7a6816f53663230075d002c666abcb /libshouldbeinlibc | |
parent | 362c7b8e02db79e6970325dc828702afac03b624 (diff) |
(fmt_past_time): Try several separators when concatenating dates & times.
Diffstat (limited to 'libshouldbeinlibc')
-rw-r--r-- | libshouldbeinlibc/timefmt.c | 15 |
1 files 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. */ |