Crossplatform time/date?

Content and general development discussion, including quest scripts and server code. TMW Classic is a project comprising the Legacy tmwAthena server & the designated improved engine server based on evolHercules.


Forum rules

This forum houses many years of development, tracing back to some of the earliest posts that exist on the board.

Its current use is for the continued development of the server and game it has always served: TMW Classic.

Post Reply
Aranince
Peon
Peon
Posts: 8
Joined: 26 Feb 2007, 20:22

Crossplatform time/date?

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

Post 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.
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, 09:55
Location: The Netherlands

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