[colobot] 62/145: Proper l10n for date/time

Didier Raboud odyx at moszumanska.debian.org
Mon Jul 11 12:56:17 UTC 2016


This is an automated email from the git hooks/post-receive script.

odyx pushed a commit to branch debian/master
in repository colobot.

commit 139592bc00534dabe4709b1baf5be6aa260edee7
Author: krzys-h <krzys_h at interia.pl>
Date:   Sat Apr 9 18:23:57 2016 +0200

    Proper l10n for date/time
---
 src/app/app.cpp                  |  8 ++++--
 src/common/misc.cpp              | 54 ----------------------------------------
 src/common/misc.h                |  4 ---
 src/level/parser/parserparam.cpp |  4 +++
 src/level/parser/parserparam.h   |  1 +
 src/level/robotmain.cpp          |  5 ++--
 src/ui/screen/screen_io.cpp      |  2 +-
 src/ui/studio.cpp                | 11 ++++----
 8 files changed, 21 insertions(+), 68 deletions(-)

diff --git a/src/app/app.cpp b/src/app/app.cpp
index 4313550..5cc047a 100644
--- a/src/app/app.cpp
+++ b/src/app/app.cpp
@@ -1813,9 +1813,13 @@ void CApplication::SetLanguage(Language language)
 
     char* defaultLocale = setlocale(LC_ALL, ""); // Load system locale
     GetLogger()->Debug("Default system locale: %s\n", defaultLocale);
+    if (!locale.empty()) // Override system locale?
+    {
+        setlocale(LC_ALL, locale.c_str());
+    }
     setlocale(LC_NUMERIC, "C"); // Force numeric locale to "C" (fixes decimal point problems)
-    char* systemLocale = setlocale(LC_ALL, nullptr); // Get current locale configuration
-    GetLogger()->Debug("Setting locale: %s\n", systemLocale);
+    std::string systemLocale = setlocale(LC_ALL, nullptr); // Get current locale configuration
+    GetLogger()->Debug("Setting locale: %s\n", systemLocale.c_str());
     // Update C++ locale
     try
     {
diff --git a/src/common/misc.cpp b/src/common/misc.cpp
index e96f58e..578b4a6 100644
--- a/src/common/misc.cpp
+++ b/src/common/misc.cpp
@@ -186,55 +186,6 @@ char GetToLower(char letter)
     return tolower(letter);
 }
 
-
-// Converting time to string.
-
-void TimeToAscii(time_t time, char *buffer)
-{
-    struct tm   when;
-    int         year;
-
-    when = *localtime(&time);
-    year = when.tm_year+1900;
-    if ( year < 2000 )  year -= 1900;
-    else                year -= 2000;
-    char        format[10];
-    int         hour;
-
-    hour = when.tm_hour;  // 0..23
-    if ( hour < 12 )  // morning?
-    {
-        strcpy(format, "am");
-    }
-    else    // afternoon?
-    {
-        strcpy(format, "pm");
-        hour -= 12;  // 0..11
-    }
-    if ( hour == 0 )  hour = 12;
-
-    sprintf(buffer, "%.2d.%.2d.%.2d %.2d:%.2d %s",
-                    when.tm_mon+1, when.tm_mday, year,
-                    hour, when.tm_min, format);
-}
-
-// Converting time to string.
-
-void TimeToAsciiClean(time_t time, char *buffer)
-{
-    struct tm   when;
-    int         year;
-
-    when = *localtime(&time);
-    year = when.tm_year+1900;
-    if ( year < 2000 )  year -= 1900;
-    else                year -= 2000;
-
-    sprintf(buffer, "%.2d%.2d%.2d%.2d%.2d",
-                    year, when.tm_mon+1, when.tm_mday,
-                    when.tm_hour, when.tm_min);
-}
-
 std::string TimeFormat(float time)
 {
     int minutes = floor(time/60);
@@ -254,8 +205,3 @@ void AddExt(char* filename, const char* ext)
     if ( strchr(filename, '.') != nullptr )  return;  // already an extension?
     strcat(filename, ext);
 }
-
-int GetCurrentTimestamp()
-{
-    return std::chrono::seconds(std::time(nullptr)).count();
-}
diff --git a/src/common/misc.h b/src/common/misc.h
index d292781..4177f3d 100644
--- a/src/common/misc.h
+++ b/src/common/misc.h
@@ -31,10 +31,6 @@ extern char GetNoAccent(char letter);
 extern char GetToUpper(char letter);
 extern char GetToLower(char letter);
 
-extern void TimeToAscii(time_t time, char *buffer);
-extern void TimeToAsciiClean(time_t time, char *buffer);
 extern std::string TimeFormat(float time);
 
 extern void AddExt(char* filename, const char* ext);
-
-extern int GetCurrentTimestamp();
diff --git a/src/level/parser/parserparam.cpp b/src/level/parser/parserparam.cpp
index 317d388..82e6e49 100644
--- a/src/level/parser/parserparam.cpp
+++ b/src/level/parser/parserparam.cpp
@@ -50,6 +50,10 @@ CLevelParserParam::CLevelParserParam(int value)
   : m_value(boost::lexical_cast<std::string>(value))
 {}
 
+CLevelParserParam::CLevelParserParam(long value)
+    : m_value(boost::lexical_cast<std::string>(value))
+{}
+
 CLevelParserParam::CLevelParserParam(float value)
   : m_value(boost::lexical_cast<std::string>(value))
 {}
diff --git a/src/level/parser/parserparam.h b/src/level/parser/parserparam.h
index f620d84..55a2f44 100644
--- a/src/level/parser/parserparam.h
+++ b/src/level/parser/parserparam.h
@@ -54,6 +54,7 @@ public:
     //! Create param with given value
     //@{
     CLevelParserParam(int value);
+    CLevelParserParam(long value);
     CLevelParserParam(float value);
     CLevelParserParam(std::string value);
     CLevelParserParam(bool value);
diff --git a/src/level/robotmain.cpp b/src/level/robotmain.cpp
index b59cc1f..e2afb5b 100644
--- a/src/level/robotmain.cpp
+++ b/src/level/robotmain.cpp
@@ -4646,7 +4646,7 @@ bool CRobotMain::IOWriteScene(std::string filename, std::string filecbot, std::s
 
 
     line = MakeUnique<CLevelParserLine>("Created");
-    line->AddParam("date", MakeUnique<CLevelParserParam>(GetCurrentTimestamp()));
+    line->AddParam("date", MakeUnique<CLevelParserParam>(time(nullptr)));
     levelParser.AddLine(std::move(line));
 
     line = MakeUnique<CLevelParserLine>("Mission");
@@ -5700,7 +5700,8 @@ void CRobotMain::Autosave()
     std::string dir = m_playerProfile->GetSaveFile("autosave" + boost::lexical_cast<std::string>(id));
 
     char timestr[100];
-    TimeToAscii(time(nullptr), timestr);
+    time_t now = time(nullptr);
+    strftime(timestr, 99, "%x %X", localtime(&now));
     std::string info = std::string("[AUTOSAVE] ")+timestr;
 
     m_playerProfile->SaveScene(dir, info);
diff --git a/src/ui/screen/screen_io.cpp b/src/ui/screen/screen_io.cpp
index 749a654..19fc79d 100644
--- a/src/ui/screen/screen_io.cpp
+++ b/src/ui/screen/screen_io.cpp
@@ -81,7 +81,7 @@ void CScreenIO::IOReadName()
     }
 
     time(&now);
-    TimeToAsciiClean(now, line);
+    strftime(line, 99, "%y%m%d%H%M", localtime(&now));
     sprintf(name, "%s - %s %d", line, resume.c_str(), m_main->GetLevelRank());
 
     pe->SetText(name);
diff --git a/src/ui/studio.cpp b/src/ui/studio.cpp
index 1b7da4e..ff34ea4 100644
--- a/src/ui/studio.cpp
+++ b/src/ui/studio.cpp
@@ -1282,9 +1282,9 @@ void CStudio::AdjustDialog()
         {
             pli->SetPos(ppos);
             pli->SetDim(ddim);
-            pli->SetTabs(0, ddim.x-(50.0f+130.0f+16.0f)/640.0f);
+            pli->SetTabs(0, ddim.x-(50.0f+140.0f+16.0f)/640.0f);
             pli->SetTabs(1,  50.0f/640.0f, Gfx::TEXT_ALIGN_RIGHT);
-            pli->SetTabs(2, 130.0f/640.0f);
+            pli->SetTabs(2, 140.0f/640.0f);
 //?         pli->ShowSelect();
         }
 
@@ -1575,7 +1575,7 @@ void CStudio::UpdateDialogList()
     CWindow*        pw;
     CList*          pl;
     int             i = 0;
-    char            time[100];
+    char            timestr[100];
 
     pw = static_cast< CWindow* >(m_interface->SearchControl(EVENT_WINDOW9));
     if ( pw == nullptr )  return;
@@ -1590,8 +1590,9 @@ void CStudio::UpdateDialogList()
     for (auto& prog : programs)
     {
         std::ostringstream temp;
-        TimeToAscii(CResourceManager::GetLastModificationTime(SearchDirectory(false) + prog), time);
-        temp << prog << '\t' << CResourceManager::GetFileSize(SearchDirectory(false) + prog) << "  \t" << time;
+        time_t now = CResourceManager::GetLastModificationTime(SearchDirectory(false) + prog);
+        strftime(timestr, 99, "%x %X", localtime(&now));
+        temp << prog << '\t' << CResourceManager::GetFileSize(SearchDirectory(false) + prog) << "  \t" << timestr;
         pl->SetItemName(i++, temp.str().c_str());
     }
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/colobot.git



More information about the Pkg-games-commits mailing list