From ca107bf159c3a288e3a32ddd0ad0da5c88b880cf Mon Sep 17 00:00:00 2001 From: Marianne Gagnon Date: Mon, 5 Oct 2015 19:36:39 -0400 Subject: [PATCH] Translatable DateTime (see #2335) --- src/utils/time.cpp | 16 ++++++++++++++++ src/utils/time.hpp | 10 ++-------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/utils/time.cpp b/src/utils/time.cpp index 86cf7c056..18861943c 100644 --- a/src/utils/time.cpp +++ b/src/utils/time.cpp @@ -19,6 +19,7 @@ #include "utils/time.hpp" #include "graphics/irr_driver.hpp" +#include "utils/translation.hpp" #include @@ -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, ...). diff --git a/src/utils/time.hpp b/src/utils/time.hpp index 9b36ace8b..5f63b3a3f 100644 --- a/src/utils/time.hpp +++ b/src/utils/time.hpp @@ -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.