Used time_t as the time type on all platforms to avoid

casting; added function to convert time to a readable
string to the namespace; and cleaned up code in addon.


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@9528 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2011-08-16 04:49:06 +00:00
parent 37e3c64259
commit 1708aeaafb
2 changed files with 17 additions and 14 deletions

View File

@ -132,8 +132,5 @@ void Addon::writeXML(std::ofstream *out_stream)
// ----------------------------------------------------------------------------
std::string Addon::getDateAsString() const
{
const struct tm *t = gmtime((time_t*)&m_date);
char s[16];
strftime(s, 128, "%d.%m.%Y", t);
return s;
return Time::toString(m_date);
} // getDateAsString

View File

@ -23,27 +23,33 @@
#ifdef WIN32
# define _WINSOCKAPI_
# include <windows.h>
# include <time.h>
#else
# include <stdint.h>
# include <sys/time.h>
#endif
class Time
#include <string>
namespace Time
{
public:
#ifdef WIN32
typedef unsigned __int64 TimeType;
#else
typedef time_t TimeType;
#endif
typedef time_t TimeType;
/** Converts the time in this object to a human readable string. */
static std::string toString(const TimeType &tt)
{
const struct tm *t = gmtime(&tt);
char s[16];
strftime(s, sizeof(s), "%d.%m.%Y", t);
return s;
} // toString
// ------------------------------------------------------------------------
static TimeType getTimeSinceEpoch()
{
#ifdef WIN32
FILETIME ft;
GetSystemTimeAsFileTime(&ft);
TimeType t = ft.dwHighDateTime;
__int64 t = ft.dwHighDateTime;
t <<= 32;
t /= 10;
// The Unix epoch starts on Jan 1 1970. Need to subtract
@ -66,6 +72,6 @@ public:
#endif
}; // getTimeSinceEpoch
}; // class time
}; // namespace time
#endif