From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5728 invoked from network); 5 Nov 2007 14:46:29 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.3 (2007-08-08) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.3 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 5 Nov 2007 14:46:29 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 90713 invoked from network); 5 Nov 2007 14:46:23 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 5 Nov 2007 14:46:23 -0000 Received: (qmail 5473 invoked by alias); 5 Nov 2007 14:46:16 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 24059 Received: (qmail 5458 invoked from network); 5 Nov 2007 14:46:16 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 5 Nov 2007 14:46:16 -0000 Received: (qmail 90007 invoked from network); 5 Nov 2007 14:46:15 -0000 Received: from smtp009.mail.ukl.yahoo.com (217.12.11.63) by a.mx.sunsite.dk with SMTP; 5 Nov 2007 14:46:09 -0000 Received: (qmail 94111 invoked from network); 5 Nov 2007 14:45:35 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.co.uk; h=Received:X-YMail-OSG:Received:In-reply-to:From:References:To:Subject:Date:Message-ID; b=1bYk9Fxxz1w1XzQifpRBwjJsB1tPIZXD0J/J+dMm6hLo3kVYg7HghOn2riGdZVWP+lVv8cFGnAig4nd8psxg7jFo89cEYukpxfvRCn6zjMyNUAKf2SG165SWV1pq1WyannYpueo8lzHCKlaEFe6EdBuA5VP5hZ8yoGhwyD44OWA= ; Received: from unknown (HELO thecus) (okiddle@89.48.34.16 with plain) by smtp009.mail.ukl.yahoo.com with SMTP; 5 Nov 2007 14:45:35 -0000 X-YMail-OSG: oaPLtH0VM1neZG6orjbEg0OqT.E5p22ONlV.E1Y.slz2W8Bhb9cguyWJTEb0FLqBv5Mid0FpZw-- Received: from opk (helo=thecus) by thecus with local-esmtp (Exim 4.63) (envelope-from ) id 1Ip3D5-0000dW-5b for zsh-workers@sunsite.dk; Mon, 05 Nov 2007 14:45:51 +0000 In-reply-to: <20071104171456.5d873459.p.w.stephenson@ntlworld.com> From: Oliver Kiddle References: <22003.1193931601@dcle12> <20071101155035.GA27981@sc.homeunix.net> <23800.1193938673@thecus> <20071104171456.5d873459.p.w.stephenson@ntlworld.com> To: Zsh workers Subject: Re: PATCH: support for nanosecond timestamps Date: Mon, 05 Nov 2007 14:45:50 +0000 Message-ID: <2449.1194273950@thecus> Peter Stephenson wrote: > %N seems reasonable, although I'm wondering if we might actually be > better off with a specification for floating point seconds; we could > then use the same thing in zsh/datetime where we only get microsecond > resolution from gettimeofday(). Either way, it would probably be good > to add this to ztrftime() and expand the interface to include a > (possibly NULL) pointer to whatever gives the extra resolution. Would > it be too horrible to allow formats like "%.9s"? We'd have to restrict > it to %S and %s which are the only two where it makes sense, and we > would have to decide what to do about E and O modifiers and glibc flag > additions; simply passing them straight through and not allowing a > fractional second in such cases would probably be good enough. How about the following as an initial step? This only adds %N. I've expanded the ztrftime interface with a long for nanoseconds. That seemed as good as any pointer given that 0 is going to be the default value. The only cases where I've not made it pass 0 is stat and prompt expansion (where we have gettimeofday). So the datetime module is unchanged. Formats like %.9s make a certain amount of logical sense though you might expect that to output the seconds too, e.g.: 23.562827621 It might be better to allow %6N and %3N given that %N is a non-standard extension already. The E and 0 modifiers don't seem to work for me, are they supposed to? Oliver Index: Src/prompt.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/prompt.c,v retrieving revision 1.43 diff -u -r1.43 prompt.c --- Src/prompt.c 22 Oct 2007 10:22:19 -0000 1.43 +++ Src/prompt.c 5 Nov 2007 14:03:17 -0000 @@ -210,6 +210,8 @@ char *ss, *hostnam; int t0, arg, test, sep, j, numjobs; struct tm *tm; + struct timeval timev; + struct timezone dummy; time_t timet; Nameddir nd; @@ -529,8 +531,8 @@ tmfmt = "%l:%M%p"; break; } - timet = time(NULL); - tm = localtime(&timet); + gettimeofday(&timev, &dummy); + tm = localtime((const time_t*) &timev.tv_sec); /* * Hack because strftime won't say how * much space it actually needs. Try to add it @@ -540,7 +542,8 @@ */ for(j = 0, t0 = strlen(tmfmt)*8; j < 3; j++, t0*=2) { addbufspc(t0); - if (ztrftime(bp, t0, tmfmt, tm) >= 0) + if (ztrftime(bp, t0, tmfmt, tm, 1000 * timev.tv_usec) + >= 0) break; } /* There is enough room for this because addbufspc(t0) Index: Src/utils.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/utils.c,v retrieving revision 1.169 diff -u -r1.169 utils.c --- Src/utils.c 31 Oct 2007 06:22:57 -0000 1.169 +++ Src/utils.c 5 Nov 2007 14:03:18 -0000 @@ -2357,7 +2357,7 @@ /**/ mod_export int -ztrftime(char *buf, int bufsize, char *fmt, struct tm *tm) +ztrftime(char *buf, int bufsize, char *fmt, struct tm *tm, long nsecs) { int hr12, decr; #ifndef HAVE_STRFTIME @@ -2425,6 +2425,12 @@ *buf++ = '0' + tm->tm_min / 10; *buf++ = '0' + tm->tm_min % 10; break; + case 'N': + if (ztrftimebuf(&bufsize, 9)) + return 0; + sprintf(buf, "%09ld", nsecs); + buf += 9; + break; case 'S': *buf++ = '0' + tm->tm_sec / 10; *buf++ = '0' + tm->tm_sec % 10; Index: Src/watch.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/watch.c,v retrieving revision 1.5 diff -u -r1.5 watch.c --- Src/watch.c 4 Apr 2005 09:59:05 -0000 1.5 +++ Src/watch.c 5 Nov 2007 14:03:18 -0000 @@ -330,7 +330,7 @@ } timet = getlogtime(u, inout); tm = localtime(&timet); - ztrftime(buf, 40, fm2, tm); + ztrftime(buf, 40, fm2, tm, 0); printf("%s", (*buf == ' ') ? buf + 1 : buf); break; case '%': Index: Src/Builtins/sched.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/Builtins/sched.c,v retrieving revision 1.13 diff -u -r1.13 sched.c --- Src/Builtins/sched.c 6 Jul 2007 21:52:40 -0000 1.13 +++ Src/Builtins/sched.c 5 Nov 2007 14:03:18 -0000 @@ -211,7 +211,7 @@ t = sch->time; tmp = localtime(&t); - ztrftime(tbuf, 20, "%a %b %e %k:%M:%S", tmp); + ztrftime(tbuf, 20, "%a %b %e %k:%M:%S", tmp, 0); if (sch->flags & SCHEDFLAG_TRASH_ZLE) flagstr = "-o "; else Index: Src/Modules/datetime.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/Modules/datetime.c,v retrieving revision 1.17 diff -u -r1.17 datetime.c --- Src/Modules/datetime.c 6 Jul 2007 21:52:40 -0000 1.17 +++ Src/Modules/datetime.c 5 Nov 2007 14:03:18 -0000 @@ -125,7 +125,7 @@ buffer = zalloc(bufsize); for (x=0; x < 4; x++) { - if (ztrftime(buffer, bufsize, argv[0], t) >= 0) + if (ztrftime(buffer, bufsize, argv[0], t, 0) >= 0) break; buffer = zrealloc(buffer, bufsize *= 2); } Index: Src/Modules/stat.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/Modules/stat.c,v retrieving revision 1.15 diff -u -r1.15 stat.c --- Src/Modules/stat.c 6 Jul 2007 21:52:40 -0000 1.15 +++ Src/Modules/stat.c 5 Nov 2007 14:03:18 -0000 @@ -188,7 +188,7 @@ /**/ static void -stattimeprint(time_t tim, char *outbuf, int flags) +stattimeprint(time_t tim, long nsecs, char *outbuf, int flags) { if (flags & STF_RAW) { sprintf(outbuf, "%ld", (unsigned long)tim); @@ -198,7 +198,7 @@ if (flags & STF_STRING) { char *oend = outbuf + strlen(outbuf); ztrftime(oend, 40, timefmt, (flags & STF_GMT) ? gmtime(&tim) : - localtime(&tim)); + localtime(&tim), nsecs); if (flags & STF_RAW) strcat(oend, ")"); } @@ -288,15 +288,27 @@ break; case ST_ATIM: - stattimeprint(sbuf->st_atime, optr, flags); +#ifdef GET_ST_ATIME_NSEC + stattimeprint(sbuf->st_atime, GET_ST_ATIME_NSEC(*sbuf), optr, flags); +#else + stattimeprint(sbuf->st_atime, 0, optr, flags); +#endif break; case ST_MTIM: - stattimeprint(sbuf->st_mtime, optr, flags); +#ifdef GET_ST_ATIME_NSEC + stattimeprint(sbuf->st_atime, GET_ST_MTIME_NSEC(*sbuf), optr, flags); +#else + stattimeprint(sbuf->st_mtime, 0, optr, flags); +#endif break; case ST_CTIM: - stattimeprint(sbuf->st_ctime, optr, flags); +#ifdef GET_ST_ATIME_NSEC + stattimeprint(sbuf->st_atime, GET_ST_CTIME_NSEC(*sbuf), optr, flags); +#else + stattimeprint(sbuf->st_ctime, 0, optr, flags); +#endif break; case ST_BLKSIZE: