From 394f3a47e464b67b17e2cb7166df066829250e88 Mon Sep 17 00:00:00 2001 From: dana Date: Wed, 20 Jun 2018 17:29:56 -0500 Subject: 43075: Support nanosecond-precision time formatting * Teach ztrftime() %9. and %N for nanoseconds * Update prompt expansion to pass sub-second times for time formatting * Update zsh/stat to pass sub-second times for atime/mtime/ctime Patch heavily based on Oliver's earlier work @ workers/24059 --- Src/utils.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'Src/utils.c') diff --git a/Src/utils.c b/Src/utils.c index b41851700..ee2ad207f 100644 --- a/Src/utils.c +++ b/Src/utils.c @@ -3224,7 +3224,7 @@ ztrftimebuf(int *bufsizeptr, int decr) /**/ mod_export int -ztrftime(char *buf, int bufsize, char *fmt, struct tm *tm, long usec) +ztrftime(char *buf, int bufsize, char *fmt, struct tm *tm, long nsec) { int hr12; #ifdef HAVE_STRFTIME @@ -3299,15 +3299,15 @@ morefmt: case '.': if (ztrftimebuf(&bufsize, digs)) return -1; - if (digs > 6) - digs = 6; - if (digs < 6) { + if (digs > 9) + digs = 9; + if (digs < 9) { int trunc; - for (trunc = 5 - digs; trunc; trunc--) - usec /= 10; - usec = (usec + 5) / 10; + for (trunc = 8 - digs; trunc; trunc--) + nsec /= 10; + nsec = (nsec + 8) / 10; } - sprintf(buf, "%0*ld", digs, usec); + sprintf(buf, "%0*ld", digs, nsec); buf += digs; break; case '\0': @@ -3369,6 +3369,12 @@ morefmt: *buf++ = '0' + tm->tm_min / 10; *buf++ = '0' + tm->tm_min % 10; break; + case 'N': + if (ztrftimebuf(&bufsize, 9)) + return -1; + sprintf(buf, "%09ld", nsec); + buf += 9; + break; case 'S': if (tm->tm_sec > 9 || !strip) *buf++ = '0' + tm->tm_sec / 10; -- cgit 1.4.1