Crossplatform time/date?

Content and general development discussion, including maps, quests, and server code from the development team.
Post Reply
Aranince
Peon
Peon
Posts: 8
Joined: 26 Feb 2007, 21:22

Crossplatform time/date?

Post by Aranince » 26 Feb 2007, 23:24

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;
User avatar
Modanung
Knight
Knight
Posts: 1719
Joined: 20 May 2005, 16:51
Location: Groningen, The Netherlands
Contact:

Post by Modanung » 27 Feb 2007, 01:33

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.
If you're looking for 3D FOSS games be sure to check out LucKey Productions on itch.io
User avatar
Avaniel
Peon
Peon
Posts: 40
Joined: 20 Aug 2006, 10:55
Location: The Netherlands

Post by Avaniel » 27 Feb 2007, 02:05

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. :)
First they ignore you. Then they laugh at you. Then you swing your +150 axe. Then you win.
Post Reply