diff options
author | Peter Stephenson <pws@zsh.org> | 2014-07-30 12:10:15 +0100 |
---|---|---|
committer | Peter Stephenson <pws@zsh.org> | 2014-07-30 12:10:15 +0100 |
commit | d3d091029367d7bf3c413330a2e93d720614d211 (patch) | |
tree | bcbf3a576dea7de1259114fc5e8df6270350fe16 /Src/utils.c | |
parent | 0442410c681b6b4e9ca0d25b22ed78e7989d5e29 (diff) | |
download | zsh-d3d091029367d7bf3c413330a2e93d720614d211.tar.gz zsh-d3d091029367d7bf3c413330a2e93d720614d211.tar.xz zsh-d3d091029367d7bf3c413330a2e93d720614d211.zip |
32918: add %. to ztrftime for use in prompts
Diffstat (limited to 'Src/utils.c')
-rw-r--r-- | Src/utils.c | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/Src/utils.c b/Src/utils.c index cef2abef8..aa978e6b9 100644 --- a/Src/utils.c +++ b/Src/utils.c @@ -2710,7 +2710,7 @@ ztrftimebuf(int *bufsizeptr, int decr) /**/ mod_export int -ztrftime(char *buf, int bufsize, char *fmt, struct tm *tm) +ztrftime(char *buf, int bufsize, char *fmt, struct tm *tm, long usec) { int hr12; #ifdef HAVE_STRFTIME @@ -2729,6 +2729,7 @@ ztrftime(char *buf, int bufsize, char *fmt, struct tm *tm) while (*fmt) if (*fmt == '%') { int strip; + int digs = 3; fmt++; if (*fmt == '-') { @@ -2736,6 +2737,17 @@ ztrftime(char *buf, int bufsize, char *fmt, struct tm *tm) fmt++; } else strip = 0; + if (idigit(*fmt)) { + /* Digit --- only useful with . */ + char *dstart = fmt; + char *dend = fmt+1; + while (idigit(*dend)) + dend++; + if (*dend == '.') { + fmt = dend; + digs = atoi(dstart); + } + } /* * Assume this format will take up at least two * characters. Not always true, but if that matters @@ -2745,6 +2757,20 @@ ztrftime(char *buf, int bufsize, char *fmt, struct tm *tm) if (ztrftimebuf(&bufsize, 2)) return -1; switch (*fmt++) { + case '.': + if (ztrftimebuf(&bufsize, digs)) + return -1; + if (digs > 6) + digs = 6; + if (digs < 6) { + int trunc; + for (trunc = 5 - digs; trunc; trunc--) + usec /= 10; + usec = (usec + 5) / 10; + } + sprintf(buf, "%0*ld", digs, usec); + buf += digs; + break; case 'd': if (tm->tm_mday > 9 || !strip) *buf++ = '0' + tm->tm_mday / 10; |