Implement fallback mechanism to set the time zone to default time zone 18/154618/1 accepted/tizen_3.0_common accepted/tizen_3.0_mobile accepted/tizen_3.0_tv accepted/tizen_3.0_wearable accepted/tizen/3.0/common/20171019.135633 accepted/tizen/3.0/mobile/20171019.104509 accepted/tizen/3.0/tv/20171019.104537 accepted/tizen/3.0/wearable/20171019.104547 submit/tizen_3.0/20171018.014246
authorHyunjee Kim <hj0426.kim@samsung.com>
Tue, 10 Oct 2017 06:09:10 +0000 (15:09 +0900)
committerMyoungJune Park <mj2004.park@samsung.com>
Wed, 11 Oct 2017 01:01:38 +0000 (01:01 +0000)
Change-Id: I32df21864719fe72b48149549539d0bad455e4c7
Signed-off-by: Hyunjee Kim <hj0426.kim@samsung.com>
src/utils_i18n_timezone.cpp

index 23b4494b4e3d545410a38cf4f4449f436cee441d..c4a9fb1c7490bd1eaf6b696a975846ee70d1cc11 100755 (executable)
@@ -22,6 +22,7 @@
 #include <utils_i18n_private.h>
 #include <utils_i18n_ustring.h>
 
+#include <unistd.h>
 #include <unicode/ustdio.h>
 #include <unicode/ucal.h>
 #include <unicode/timezone.h>
@@ -191,10 +192,34 @@ int i18n_timezone_get_equivalent_id(const char *timezone_id, int32_t index,
     return I18N_ERROR_NONE;
 }
 
+#define TZDEFAULT "/opt/etc/localtime"
+#define TZZONEINFO "/usr/share/zoneinfo/"
+
 int i18n_timezone_create_default(i18n_timezone_h *timezone)
 {
     retv_if(timezone == NULL, I18N_ERROR_INVALID_PARAMETER);
     *timezone = TimeZone::createDefault();
+       //Implement fallback mechanism to set the time zone to default time zone
+       char* zoneInfo = NULL;
+       UnicodeString TimezoneID;
+       ((TimeZone *) *timezone)->getID(TimezoneID);
+       const UChar *tid = TimezoneID.getTerminatedBuffer();
+       char tzpath[1024];
+       int32_t ret = (int32_t) readlink(TZDEFAULT, tzpath, sizeof(tzpath) - 1);
+       if(ret > 0)
+       {
+               tzpath[ret] ='\0';
+               int32_t zoneinfolen = strlen(TZZONEINFO);
+               zoneInfo = tzpath + zoneinfolen;
+       }
+       if(tid == NULL) {
+               *timezone = TimeZone::createTimeZone(zoneInfo);
+               return I18N_ERROR_NONE;
+       }
+       int32_t ulen = i18n_ustring_get_length(tid);
+       if(ulen <= 0) {
+               *timezone = TimeZone::createTimeZone(zoneInfo);
+       }
 
     return I18N_ERROR_NONE;
 }