Change timezone format from GMT to timezone path. 66/104566/4
authorRadoslaw Czerski <r.czerski@samsung.com>
Thu, 29 Dec 2016 09:10:59 +0000 (10:10 +0100)
committerLukasz Stanislawski <l.stanislaws@samsung.com>
Wed, 4 Jan 2017 13:04:21 +0000 (05:04 -0800)
Timezones are used to get local time.
This change makes time functions to take into account DST.
Timezone path is retrieved from libug-worldclock-efl app.

Change-Id: If9cf9d5e9f2b13229175b3ec034d36ea8f8eabae
Signed-off-by: Radoslaw Czerski <r.czerski@samsung.com>
clock/inc/Model/Location.h
clock/inc/Model/WorldClock.h
clock/src/Model/WorldClock.cpp
clock/src/View/WorldClockDeleteItemsView.cpp
clock/src/View/WorldClockReorderView.cpp
clock/src/View/WorldClockView.cpp

index 2720f4c2a7860a4e1ec94f81e0b5820c7cbafc0b..c2b200cc4f21959d7a00fe825de10e1d89ed40ef 100644 (file)
@@ -29,6 +29,7 @@ namespace model {
                int y;
 
                bool summertime;
+               std::string tzpath;
        };
 } /* model */
 
index 16770c9603e10fc1d2195746a4db37d0fba45eae..d698c6ab7ac877a6bffe2edd3a5188cebdb90938 100644 (file)
@@ -191,7 +191,8 @@ namespace model {
                        enum ItemKeyType {
                                CITY,
                                COUNTRY,
-                               OFFSET
+                               OFFSET,
+                               TIMEZONE_PATH
                        };
 
                        /**
index b6713af2903d2f0f70d5cc1413c0446723d7a24a..1f71a0077cfedc1c6791e291b1a7a57c50c2d2d7 100644 (file)
@@ -371,6 +371,9 @@ const char *WorldClock::GetItemKey(int type, int no)
                case OFFSET:
                        s.append("OFFSET");
                        break;
+               case TIMEZONE_PATH:
+                       s.append("TIMEZONE_PATH");
+                       break;
                default:
                        ERR("Invalid type!");
                        return NULL;
@@ -395,6 +398,11 @@ void WorldClock::SaveItem(const model::Location *item, int i)
        if (ret != PREFERENCE_ERROR_NONE) {
                ERR("preference_set_int failed[%d]: %s", ret, get_error_message(ret));
        }
+       ret = preference_set_string(GetItemKey(TIMEZONE_PATH, i), item->tzpath.c_str());
+       if (ret != PREFERENCE_ERROR_NONE) {
+               ERR("preference_set_string failed[%d]: %s", ret, get_error_message(ret));
+               return;
+       }
 }
 
 const model::Location *WorldClock::LoadItem(int i)
@@ -403,6 +411,7 @@ const model::Location *WorldClock::LoadItem(int i)
 
        char *city_name;
        char *country_name;
+       char *timezone_path;
 
        int ret = preference_get_string(GetItemKey(CITY, i), &city_name);
        if (ret != PREFERENCE_ERROR_NONE) {
@@ -425,12 +434,22 @@ const model::Location *WorldClock::LoadItem(int i)
                delete location;
                return NULL;
        }
+       ret = preference_get_string(GetItemKey(TIMEZONE_PATH, i), &timezone_path);
+       if (ret != PREFERENCE_ERROR_NONE) {
+               ERR("preference_get_string failed[%d]: %s", ret, get_error_message(ret));
+               free(city_name);
+               free(country_name);
+               delete location;
+               return NULL;
+       }
 
        location->name = city_name;
        location->country = country_name;
+       location->tzpath = timezone_path;
 
        free(city_name);
        free(country_name);
+       free(timezone_path);
 
        return location;
 }
index 728a8c0f3d13385689cb1671424513ae1404154f..4ba41a8fa67d724756ef6f73dbdcb8032e62a35e 100644 (file)
@@ -63,7 +63,7 @@ void WorldClockDeleteItemsView::AppendItems(std::vector<const model::Location *>
        for (auto l: locations) {
                DBG();
                LocationDeleteItemData *data = new LocationDeleteItemData;
-               Time t = Time::Now().InTimezone(Time::GetTimezoneNameByOffset(l->gmt_offset_).c_str());
+               Time t = Time::Now().InTimezone(l->tzpath.c_str());
                int local_timezone_offset = Time::GetTimezoneOffset(Time::GetCurrentTimezone().c_str());
                ss.str(std::string());
                ss.clear();
@@ -111,7 +111,7 @@ Evas_Object *WorldClockDeleteItemsView::ContentGet(void *data, Evas_Object *obj,
        LocationDeleteItemData *ldid = static_cast<LocationDeleteItemData *>(data);
 
        if (!strcmp(part, "time")) {
-               Time t = Time::Now().InTimezone(Time::GetTimezoneNameByOffset(ldid->gmt_offset).c_str());
+               Time t = Time::Now().InTimezone(ldid->location->tzpath.c_str());
 
                ldid->time = elm_table_add(obj);
                evas_object_size_hint_align_set(ldid->time, 0.0, 0.0);
index 81b3c360fd11c38bb1a859b802cdf0b84663785c..fa270fae22f0b262cc28772f8f3d2c093ffd86f4 100644 (file)
@@ -79,7 +79,7 @@ void WorldClockReorderView::AppendItems(
 
        for (auto it = locations.begin(); it != locations.end(); it++) {
                LocationReorderItemData *lrid = new LocationReorderItemData;
-               Time t = Time::Now().InTimezone(Time::GetTimezoneNameByOffset((*it)->gmt_offset_).c_str());
+               Time t = Time::Now().InTimezone((*it)->tzpath.c_str());
                int local_timezone_offset = Time::GetTimezoneOffset(Time::GetCurrentTimezone().c_str());
 
                ss.str(std::string());
@@ -177,7 +177,7 @@ Evas_Object *WorldClockReorderView::ContentGet(void *data,
        LocationReorderItemData *lrid = static_cast<LocationReorderItemData *>(data);
 
        if (!strcmp(part, "time")) {
-               Time t = Time::Now().InTimezone(Time::GetTimezoneNameByOffset(lrid->gmt_offset).c_str());
+               Time t = Time::Now().InTimezone(lrid->location->tzpath.c_str());
 
                lrid->time = elm_table_add(obj);
                evas_object_size_hint_align_set(lrid->time, 0.0, 0.0);
index df7f4926502196f4f8bd9d4a8330be71a343dfed..d4b306efe6f526fea18ec33e235076703d7e12c4 100644 (file)
@@ -72,8 +72,8 @@ void WorldClockView::CreateCustomLocationsList(Evas_Object *parent)
 void WorldClockView::AppendItemToCustomList(const model::Location *location)
 {
        LocationItemData *data = new LocationItemData;
-       Time t = Time::Now().InTimezone(
-                       Time::GetTimezoneNameByOffset(location->gmt_offset_).c_str());
+
+       Time t = Time::Now().InTimezone(location->tzpath.c_str());
        int local_timezone_offset = Time::GetTimezoneOffset(Time::GetCurrentTimezone().c_str());
        std::stringstream ss;
 
@@ -150,7 +150,7 @@ Evas_Object *WorldClockView::ContentGet(void *data, Evas_Object *obj, const char
                elm_table_pack(lid->time, ampm, 2, 0, 1, 1);
                elm_table_pack(lid->time, dynamic_padding, 3, 0, 1, 1);
 
-               Time t = Time::Now().InTimezone(Time::GetTimezoneNameByOffset(lid->gmt_offset).c_str());
+               Time t = Time::Now().InTimezone(lid->location->tzpath.c_str());
 
                std::string timezone_time;
                std::string meridiem;
@@ -385,6 +385,7 @@ void WorldClockView::AddLocationReplayCb(app_control_h request, app_control_h re
        char *city_name;
        char *country_name;
        char *timezone;
+       char *tzpath;
        char **timezone_splited;
 
        int h = 0;
@@ -400,11 +401,22 @@ void WorldClockView::AddLocationReplayCb(app_control_h request, app_control_h re
        ret = app_control_get_extra_data(reply, "country_name", &country_name);
        if (ret != APP_CONTROL_ERROR_NONE) {
                ERR("app_control_get_extra_data failed[%d]: %s", ret, get_error_message(ret));
+               free(city_name);
                return;
        }
        ret = app_control_get_extra_data(reply, "timezone", &timezone);
        if (ret != APP_CONTROL_ERROR_NONE) {
                ERR("app_control_get_extra_data failed[%d]: %s", ret, get_error_message(ret));
+               free(city_name);
+               free(country_name);
+               return;
+       }
+       ret = app_control_get_extra_data(reply, "tzpath", &tzpath);
+       if (ret != APP_CONTROL_ERROR_NONE) {
+               ERR("app_control_get_extra_data failed[%d]: %s", ret, get_error_message(ret));
+               free(city_name);
+               free(country_name);
+               free(timezone);
                return;
        }
 
@@ -418,10 +430,8 @@ void WorldClockView::AddLocationReplayCb(app_control_h request, app_control_h re
        }
 
        int gmt_offset = (60*h + min) * ((timezone[0] == '-') ? (-1) : (1));
-       model::Location *l = new model::Location{
-               std::string(city_name),
-               std::string(country_name),
-               gmt_offset,};
+       model::Location *l = new model::Location{ std::string(city_name),
+               std::string(country_name), gmt_offset, 0, 0, false, std::string(tzpath),};
 
        WorldClockView *view = static_cast<WorldClockView *>(user_data);
        view->SetItemToAdd(l);
@@ -430,6 +440,7 @@ void WorldClockView::AddLocationReplayCb(app_control_h request, app_control_h re
        free(city_name);
        free(country_name);
        free(timezone);
+       free(tzpath);
 }
 
 void WorldClockView::AddButtonClicked(void *data, Evas_Object *obj, void *event_info)