From: Frédéric Marchal Date: Mon, 14 Dec 2009 10:07:35 +0000 (+0000) Subject: Ported r161 from branches/v2_2_6_1 (fix regression in sarg-date) X-Git-Tag: v2_2_7~50 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9e41ca7eb660b9c6a6e5d0e271bb707552a4097a;p=thirdparty%2Fsarg.git Ported r161 from branches/v2_2_6_1 (fix regression in sarg-date) --- diff --git a/documentation/util.txt b/documentation/util.txt index 5b872de..9fa5c8e 100644 --- a/documentation/util.txt +++ b/documentation/util.txt @@ -329,6 +329,23 @@ bytes long. +/*! \fn void formatdate(char *date,int date_size,int year,int month,int day,int hour,int minute,int second) +Format a date to display it in the report. + +\param date The buffer to write the formatted date into. +\param date_size The size of the buffer. +\param year The absolute year to format. It must be greater than 1900. +\param month The month to format. It must be between 1 and 12. +\param day The day to format starting from 1. +\param hour The hour to format. +\param minute The minute to format. +\param second The second to format. +*/ + + + + + /*! \fn void obtuser(const char *dirname, const char *name, char *tuser) Get the number of entries stored in a connection data directory. The number is read from the sarg-users file of the connection data's directory. diff --git a/include/defs.h b/include/defs.h index 4ce1f9b..4e6428b 100755 --- a/include/defs.h +++ b/include/defs.h @@ -144,6 +144,7 @@ void url_module(const char *url, char *w2); void strip_latin(char *line); char *buildtime(long long int elap); void obtdate(const char *dirname, const char *name, char *data); +void formatdate(char *date,int date_size,int year,int month,int day,int hour,int minute,int second); void obtuser(const char *dirname, const char *name, char *tuser); void obttotal(const char *dirname, const char *name, char *tbytes, char *tuser, char *media); void version(void); diff --git a/index.c b/index.c index 3e756d2..a28df42 100644 --- a/index.c +++ b/index.c @@ -207,6 +207,7 @@ void make_index(void) obtuser(outdir,direntp->d_name,tuser); obttotal(outdir,direntp->d_name,tbytes,tuser,media); if (sscanf(data,"%d-%d-%d %d:%d:%d",&iyear,&imonth,&iday,&ihour,&iminute,&isecond)==6) { + formatdate(data,sizeof(data),iyear,imonth,iday,ihour,iminute,isecond); fprintf(fp_tmp,"%04d%02d%02d%02d%02d%02d;%s;%s;%s;%s;%s;%s\n",iyear,imonth,iday,ihour,iminute,isecond, direntp->d_name, data, tuser, tbytes, media,newname); } else { /* diff --git a/util.c b/util.c index 5e1d1a2..ad7601c 100644 --- a/util.c +++ b/util.c @@ -640,6 +640,23 @@ void obtdate(const char *dirname, const char *name, char *data) } +void formatdate(char *date,int date_size,int year,int month,int day,int hour,int minute,int second) +{ + struct tm ltm; + time_t curtime; + + memset(<m,0,sizeof(ltm)); + ltm.tm_year=year-1900; + ltm.tm_mon=month-1; + ltm.tm_mday=day; + ltm.tm_hour=hour; + ltm.tm_min=minute; + ltm.tm_sec=second; + curtime=mktime(<m); //tm cannot be used directly because we need the date normalization made by mktime. + strftime(date,date_size,"%a %b %d %H:%M:%S %Z %Y",localtime(&curtime)); +} + + void obtuser(const char *dirname, const char *name, char *tuser) {