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:
parent
37e3c64259
commit
1708aeaafb
@ -132,8 +132,5 @@ void Addon::writeXML(std::ofstream *out_stream)
|
|||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
std::string Addon::getDateAsString() const
|
std::string Addon::getDateAsString() const
|
||||||
{
|
{
|
||||||
const struct tm *t = gmtime((time_t*)&m_date);
|
return Time::toString(m_date);
|
||||||
char s[16];
|
|
||||||
strftime(s, 128, "%d.%m.%Y", t);
|
|
||||||
return s;
|
|
||||||
} // getDateAsString
|
} // getDateAsString
|
||||||
|
@ -23,27 +23,33 @@
|
|||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
# define _WINSOCKAPI_
|
# define _WINSOCKAPI_
|
||||||
# include <windows.h>
|
# include <windows.h>
|
||||||
|
# include <time.h>
|
||||||
#else
|
#else
|
||||||
# include <stdint.h>
|
# include <stdint.h>
|
||||||
# include <sys/time.h>
|
# include <sys/time.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class Time
|
#include <string>
|
||||||
|
|
||||||
|
namespace Time
|
||||||
{
|
{
|
||||||
public:
|
typedef time_t TimeType;
|
||||||
|
|
||||||
#ifdef WIN32
|
|
||||||
typedef unsigned __int64 TimeType;
|
|
||||||
#else
|
|
||||||
typedef time_t TimeType;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
/** 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()
|
static TimeType getTimeSinceEpoch()
|
||||||
{
|
{
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
FILETIME ft;
|
FILETIME ft;
|
||||||
GetSystemTimeAsFileTime(&ft);
|
GetSystemTimeAsFileTime(&ft);
|
||||||
TimeType t = ft.dwHighDateTime;
|
__int64 t = ft.dwHighDateTime;
|
||||||
t <<= 32;
|
t <<= 32;
|
||||||
t /= 10;
|
t /= 10;
|
||||||
// The Unix epoch starts on Jan 1 1970. Need to subtract
|
// The Unix epoch starts on Jan 1 1970. Need to subtract
|
||||||
@ -66,6 +72,6 @@ public:
|
|||||||
#endif
|
#endif
|
||||||
}; // getTimeSinceEpoch
|
}; // getTimeSinceEpoch
|
||||||
|
|
||||||
}; // class time
|
}; // namespace time
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user