add vttimefmt

This commit is contained in:
rsc 2006-07-18 15:23:58 +00:00
parent 2bdefab1da
commit d20564a9a6
3 changed files with 28 additions and 0 deletions

View file

@ -488,6 +488,8 @@ uvlong vtfilegetsize(VtFile*);
int vtfilesetsize(VtFile*, u64int);
int vtfileremove(VtFile*);
extern int vttimefmt(Fmt*);
extern int chattyventi;
extern int ventidoublechecksha1;
extern int ventilogging;

View file

@ -27,6 +27,7 @@ OFILES=\
srvhello.$O\
strdup.$O\
string.$O\
time.$O\
version.$O\
zero.$O\
zeroscore.$O\

25
src/libventi/time.c Normal file
View file

@ -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);
}
}