[date-time] add a formatter for 0x0p+0

Defect Number:
    Reviewed By:
   Testing Done:
pull/482/head
Timothy Stack 7 years ago
parent 3da74b5621
commit 4b40b3f9f5

@ -54,6 +54,9 @@ TIME_FORMATS = \
"%Y/%m/%d %H:%M:%S %z" \
"%Y/%m/%d %H:%M:%S%z" \
"%Y/%m/%d %H:%M" \
"%Y %b %d %a %H:%M:%S.%L" \
"%Y %b %d %H:%M:%S.%L" \
"%Y %b %d %H:%M:%S" \
"%a %b %d %H:%M:%S %Y" \
"%a %b %d %H:%M:%S.%f %Y" \
"%a %b %d %H:%M:%S %Z %Y" \

@ -380,6 +380,26 @@ static const int year_lengths[2] = {
366
} ;
static void secs2wday(const struct timeval &tv, struct tm *res)
{
long days, rem;
time_t lcltime;
/* base decision about std/dst time on current time */
lcltime = tv.tv_sec;
days = ((long) lcltime) / SECSPERDAY;
rem = ((long) lcltime) % SECSPERDAY;
while (rem < 0) {
rem += SECSPERDAY;
--days;
}
/* compute day of week */
if ((res->tm_wday = ((EPOCH_WDAY + days) % DAYSPERWEEK)) < 0)
res->tm_wday += DAYSPERWEEK;
}
struct tm *secs2tm(time_t *tim_p, struct tm *res)
{
long days, rem;
@ -567,6 +587,7 @@ const char *date_time_scanner::scan(const char *time_dest,
}
tv_out.tv_sec = tm2sec(&tm_out->et_tm);
tv_out.tv_usec = tm_out->et_nsec / 1000;
secs2wday(tv_out, &tm_out->et_tm);
this->dts_fmt_lock = curr_time_fmt;
this->dts_fmt_len = retval - time_dest;
@ -602,6 +623,7 @@ const char *date_time_scanner::scan(const char *time_dest,
tv_out.tv_sec = tm2sec(&tm_out->et_tm);
tv_out.tv_usec = tm_out->et_nsec / 1000;
secs2wday(tv_out, &tm_out->et_tm);
this->dts_fmt_lock = curr_time_fmt;
this->dts_fmt_len = retval - time_dest;

@ -172,7 +172,48 @@ inline bool ptime_b(struct exttm *dst, const char *str, off_t &off_inout, ssize_
inline void ftime_a(char *dst, off_t &off_inout, ssize_t len, const struct exttm &tm)
{
switch (tm.et_tm.tm_wday) {
case 0:
PTIME_APPEND('S');
PTIME_APPEND('u');
PTIME_APPEND('n');
break;
case 1:
PTIME_APPEND('M');
PTIME_APPEND('o');
PTIME_APPEND('n');
break;
case 2:
PTIME_APPEND('T');
PTIME_APPEND('u');
PTIME_APPEND('e');
break;
case 3:
PTIME_APPEND('W');
PTIME_APPEND('e');
PTIME_APPEND('d');
break;
case 4:
PTIME_APPEND('T');
PTIME_APPEND('h');
PTIME_APPEND('u');
break;
case 5:
PTIME_APPEND('F');
PTIME_APPEND('r');
PTIME_APPEND('i');
break;
case 6:
PTIME_APPEND('S');
PTIME_APPEND('a');
PTIME_APPEND('t');
break;
default:
PTIME_APPEND('X');
PTIME_APPEND('X');
PTIME_APPEND('X');
break;
}
}
inline void ftime_Z(char *dst, off_t &off_inout, ssize_t len, const struct exttm &tm)

@ -121,6 +121,7 @@ size_t ftime_fmt(char *dst, size_t len, const char *fmt, const struct exttm &tm)
case '%':
ftime_char(dst, off_inout, len, '%');
break;
FTIME_FMT_CASE('a', a);
FTIME_FMT_CASE('b', b);
FTIME_FMT_CASE('S', S);
FTIME_FMT_CASE('s', s);

@ -36,6 +36,7 @@
#include "../src/lnav_util.hh"
static const char *GOOD_TIMES[] = {
"2017 May 08 Mon 18:57:57.578",
"May 01 00:00:01",
"May 10 12:00:01",
"2014-02-11 16:12:34",

Loading…
Cancel
Save