aboutsummaryrefslogtreecommitdiff
path: root/src/libventi
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2006-07-18 15:23:58 +0000
committerrsc <devnull@localhost>2006-07-18 15:23:58 +0000
commitd20564a9a6d75192ec21170f2c6cd699eb361d96 (patch)
treedfc62a2603829373cf53b5cf0d27f60fb3ddc8d6 /src/libventi
parent2bdefab1da7bc64f433cba5871fc57d5524a06e1 (diff)
downloadplan9port-d20564a9a6d75192ec21170f2c6cd699eb361d96.tar.gz
plan9port-d20564a9a6d75192ec21170f2c6cd699eb361d96.tar.bz2
plan9port-d20564a9a6d75192ec21170f2c6cd699eb361d96.zip
add vttimefmt
Diffstat (limited to 'src/libventi')
-rw-r--r--src/libventi/mkfile1
-rw-r--r--src/libventi/time.c25
2 files changed, 26 insertions, 0 deletions
diff --git a/src/libventi/mkfile b/src/libventi/mkfile
index 2e7d04b3..289262ac 100644
--- a/src/libventi/mkfile
+++ b/src/libventi/mkfile
@@ -27,6 +27,7 @@ OFILES=\
srvhello.$O\
strdup.$O\
string.$O\
+ time.$O\
version.$O\
zero.$O\
zeroscore.$O\
diff --git a/src/libventi/time.c b/src/libventi/time.c
new file mode 100644
index 00000000..2d8058f1
--- /dev/null
+++ b/src/libventi/time.c
@@ -0,0 +1,25 @@
+#include <u.h>
+#include <libc.h>
+#include <venti.h>
+
+int
+vttimefmt(Fmt *fmt)
+{
+ vlong ns;
+ Tm tm;
+
+ if(fmt->flags&FmtLong){
+ ns = nsec();
+ tm = *localtime(ns/1000000000);
+ return fmtprint(fmt, "%04d/%02d%02d %02d:%02d:%02d.%03d",
+ tm.year+1900, tm.mon+1, tm.mday,
+ tm.hour, tm.min, tm.sec,
+ (int)(ns%1000000000)/1000000);
+ }else{
+ tm = *localtime(time(0));
+ return fmtprint(fmt, "%04d/%02d%02d %02d:%02d:%02d",
+ tm.year+1900, tm.mon+1, tm.mday,
+ tm.hour, tm.min, tm.sec);
+ }
+}
+