]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Ported r161 from branches/v2_2_6_1 (fix regression in sarg-date)
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Mon, 14 Dec 2009 10:07:35 +0000 (10:07 +0000)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Mon, 14 Dec 2009 10:07:35 +0000 (10:07 +0000)
documentation/util.txt
include/defs.h
index.c
util.c

index 5b872de8d990bde36cd31565fa17996a3232d25f..9fa5c8e949291f18fb9a8f340a6913ad05980ee1 100644 (file)
@@ -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 <tt>sarg-users</tt> file of the connection data's directory.
index 4ce1f9bbae43619a0da99b3a9f4a89fe3d6efaec..4e6428bfdf76254cd334bf388e1d51e629480910 100755 (executable)
@@ -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 3e756d21f1f23155eb16278515d8f5935dbdb532..a28df4215a2a99e446bcbede9cf14b6a6645583b 100644 (file)
--- 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 5e1d1a2fa83a9e73386f8f61cb2ba50d75c2c2ad..ad7601ccbd98ea56c2b00b8a95658fdc28f5920c 100644 (file)
--- 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(&ltm,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(&ltm); //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)
 {