Page 1 of 1

Crossplatform time/date?

Posted: 26 Feb 2007, 22:24
by Aranince
Hey, I was looking at log.cpp and was wondering why you guys don't use <ctime>?

Code: Select all

    // Get the current system time
    const time_t *t;
    tm *date = localtime(t);

    // Print the log entry
    mLogFile << "["
             <<date->tm_hour
             << ":"
             <<date->tm_min
             << ":"
             <<date->tm_sec
             << "]"
             << buf
             << std::endl;

Posted: 27 Feb 2007, 00:33
by Modanung
I think it is because ctime returns the entire date, including name of the day, name of the month, number of the day and the year. While just the time in hours, minutes and seconds is enough. All that the time is needed for is know when different events occurred relative to each other.

Posted: 27 Feb 2007, 01:05
by Avaniel
Mmm, you missed a spot:
From tmw/trunk/src/log.cpp:
// Print the log entry
std::stringstream timeStr;
timeStr << "["
<< ((((tv.tv_sec / 60) / 60) % 24 < 10) ? "0" : "")
<< (int)(((tv.tv_sec / 60) / 60) % 24)
<< ":"
<< (((tv.tv_sec / 60) % 60 < 10) ? "0" : "")
<< (int)((tv.tv_sec / 60) % 60)
<< ":"
<< ((tv.tv_sec % 60 < 10) ? "0" : "")
<< (int)(tv.tv_sec % 60)
<< "."
<< (((tv.tv_usec / 10000) % 100) < 10 ? "0" : "")
<< (int)((tv.tv_usec / 10000) % 100) // Hundreds of a second
<< "] ";
I didn't write it, but that is probably the reason. But nevertheless, thanks for the input. :)