added a set_time method to format the logitem->time field
@@ -964,6 +964,23 @@ set_date (char **fdate, struct tm tm)
return 0;
}
+/* Format the broken-down time tm to a numeric time format.
+ *
+ * On error, or unable to format the given tm, 1 is returned.
+ * On success, a malloc'd format is returned. */
+static int
+set_time (char **ftime, struct tm tm)
+{
+ char buf[TIME_LEN] = "";
+
+ memset (buf, 0, sizeof (buf));
+ if (strftime (buf, TIME_LEN, "%H:%M:%S", &tm) <= 0)
+ return 1;
+ *ftime = xstrdup (buf);
+
+ return 0;
+}
+
/* Determine the parsing specifier error and construct a message out
* of it.
*
@@ -1047,12 +1064,11 @@ parse_specifier (GLogItem * logitem, char **str, const char *p, const char *end)
if (!(tkn = parse_string (&(*str), end, 1)))
return spec_err (logitem, SPEC_TOKN_NUL, *p, NULL);
- if (str_to_time (tkn, tfmt, &tm) != 0) {
+ if (str_to_time (tkn, tfmt, &tm) != 0 || set_time(&logitem->time, tm) != 0) {
spec_err (logitem, SPEC_TOKN_INV, *p, tkn);
free (tkn);
return 1;
}
- logitem->time = tkn;
break;
/* date/time as decimal, i.e., timestamps, ms/us */
case 'x':
@@ -1061,12 +1077,11 @@ parse_specifier (GLogItem * logitem, char **str, const char *p, const char *end)
if (!(tkn = parse_string (&(*str), end, 1)))
return spec_err (logitem, SPEC_TOKN_NUL, *p, NULL);
- if (str_to_time (tkn, tfmt, &tm) != 0 || set_date (&logitem->date, tm) != 0) {
+ if (str_to_time (tkn, tfmt, &tm) != 0 || set_date (&logitem->date, tm) != 0 || set_time(&logitem->time, tm) != 0) {
spec_err (logitem, SPEC_TOKN_INV, *p, tkn);
free (tkn);
return 1;
}
- logitem->time = tkn;
break;
/* Virtual Host */
case 'v':
