simsong/dfxml

ISO 8601 timestamp error

Closed this issue · 3 comments

The to8601 function does not properly add the timezone offset to the output. The function converts to localtime and then adds the "Z", however it does not add the offset thus code parsing the date output will incorrectly assume the timestamp output is in UTC when in fact the timestamp is in localtime.

   static std::string to8601(const struct timeval &ts) {
        struct tm tm;
        char buf[64];
#ifdef HAVE_LOCALTIME_R
        localtime_r(&ts.tv_sec,&tm);
#else
        time_t t = ts.tv_sec;
        tm = *localtime(&t);
#endif
        strftime(buf,sizeof(buf),"%Y-%m-%dT%H:%M:%S",&tm);
        if(ts.tv_usec>0){
            int len = strlen(buf);
            snprintf(buf+len,sizeof(buf)-len,".%06d",(int)ts.tv_usec);
        }
        strcat(buf,"Z");
        return std::string(buf);
    }

I first noticed this issue when parsing output xml from tcpflow 1.4.4.

To clarify, the function should either use gmtime_r add the 'Z' or it should use localtime and not add the 'Z' but instead add the appropriate timezone offset in one of the acceptable formats. I would prefer the gmtime_r -- when dealing with data UTC works best.

Agreed

Sent from my iPhone

On May 14, 2015, at 6:19 PM, FusionFC notifications@github.com wrote:

To clarify, the function should either use gmtime_r add the 'Z' or it should use localtime and not add the 'Z' but instead add the appropriate timezone offset in one of the acceptable formats. I would prefer the gmtime_r -- when dealing with data UTC works best.


Reply to this email directly or view it on GitHub.

fixed.