Translatable DateTime (see #2335)

This commit is contained in:
Marianne Gagnon 2015-10-05 19:36:39 -04:00
parent 6318e8c8f8
commit ca107bf159
2 changed files with 18 additions and 8 deletions

View File

@ -19,6 +19,7 @@
#include "utils/time.hpp"
#include "graphics/irr_driver.hpp"
#include "utils/translation.hpp"
#include <ctime>
@ -38,6 +39,21 @@ void StkTime::init()
m_timer->grab();
} // init
// ----------------------------------------------------------------------------
/** Converts the time in this object to a human readable string. */
std::string StkTime::toString(const TimeType &tt)
{
const struct tm *t = gmtime(&tt);
core::stringw w_date_format = translations->w_gettext(N_("%d/%m/%Y"));
core::stringc c_date_format(w_date_format.c_str());
char s[64];
strftime(s, 64, c_date_format.c_str(), t);
return s;
} // toString
// ----------------------------------------------------------------------------
/** Returns a time based on an arbitrary 'epoch' (e.g. could be start
* time of the application, 1.1.1970, ...).

View File

@ -51,14 +51,8 @@ public:
static void init();
static void getDate(int *day=NULL, int *month=NULL, int *year=NULL);
/** 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, 16, "%x", t);
return s;
} // toString
/** Converts the time in this object to a human readable string. */
static std::string toString(const TimeType &tt);
// ------------------------------------------------------------------------
/** Returns the number of seconds since 1.1.1970. This function is used
* to compare access times of files, e.g. news, addons data etc.