improve Time.h dummy implementation.
authorLukasz Stanislawski <l.stanislaws@samsung.com>
Sun, 11 Sep 2016 09:38:58 +0000 (11:38 +0200)
committerLukasz Stanislawski <l.stanislaws@samsung.com>
Mon, 12 Sep 2016 11:14:20 +0000 (13:14 +0200)
Instead of returning hardcoded values now return real values.
This code will be changed when proper icu support will be added.

Change-Id: Id056526136a01f302510284dfe0d69349a8fffdf

clock/src/Utils/Time.cpp

index ba3f1f1..4d5f80c 100644 (file)
@@ -1,5 +1,6 @@
 #include "Utils/Time.h"
 #include <utils_i18n.h>
+#include <cstring>
 
 using namespace utils;
 
@@ -23,9 +24,9 @@ std::string Time::Format(enum Format format) const
 {
        switch (format) {
                case FORMAT_12H:
-                       return getFormattedTime("HH:mm");
-               case FORMAT_24H:
                        return getFormattedTime("h:mm");
+               case FORMAT_24H:
+                       return getFormattedTime("HH:mm");
        }
        abort();
        return "";
@@ -33,10 +34,17 @@ std::string Time::Format(enum Format format) const
 
 std::string Time::Meridiem() const
 {
-       return "AM";
+       return Hour >= 12 ? "PM" : "AM";
 }
 
 std::string Time::getFormattedTime(const char *icu_format) const
 {
-       return "12:01";
+       char buf[32] = {0,};
+       if (!strcmp(icu_format, "HH:mm")) {
+               snprintf(buf, sizeof(buf), "%d:%d", Hour, Min);
+       }
+       if (!strcmp(icu_format, "h:mm")) {
+               snprintf(buf, sizeof(buf), "%d:%d", Hour > 12 ? Hour - 12 : Hour, Min);
+       }
+       return buf;
 }