aboutsummaryrefslogtreecommitdiff
path: root/lib/lib.c
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2018-06-28 16:57:21 -0700
committerRob Landley <rob@landley.net>2018-07-04 14:24:24 -0500
commit4d673c9ad4c65c329a85ebb19c2812ae93183099 (patch)
tree0dba43542152b2f06805340104bf25390193cf51 /lib/lib.c
parent7771e94e2a082726142387476937d7f136f65147 (diff)
downloadtoybox-4d673c9ad4c65c329a85ebb19c2812ae93183099.tar.gz
diff: add timestamps to the ---/+++ lines and --color.
(My apologies for mixing these two unrelated changes up.)
Diffstat (limited to 'lib/lib.c')
-rw-r--r--lib/lib.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/lib/lib.c b/lib/lib.c
index 41ecb1de..88dd13a0 100644
--- a/lib/lib.c
+++ b/lib/lib.c
@@ -1394,3 +1394,12 @@ long long millitime(void)
clock_gettime(CLOCK_MONOTONIC, &ts);
return ts.tv_sec*1000+ts.tv_nsec/1000000;
}
+
+// Formats `ts` in ISO format ("2018-06-28 15:08:58.846386216 -0700").
+char *format_iso_time(char *buf, size_t len, struct timespec *ts)
+{
+ strftime(buf, len, "%F %T", localtime(&(ts->tv_sec)));
+ sprintf(buf+strlen(buf), ".%09ld ", ts->tv_nsec);
+ strftime(buf+strlen(buf), len-strlen(buf), "%z", localtime(&(ts->tv_sec)));
+ return buf;
+}