Implement fallback mechanism to set the time zone to default time zone 63/154363/4 accepted/tizen/unified/20171018.062744 submit/tizen/20171018.014319
authorHyunjee Kim <hj0426.kim@samsung.com>
Tue, 10 Oct 2017 06:09:10 +0000 (15:09 +0900)
committerhyunjee Kim <hj0426.kim@samsung.com>
Wed, 18 Oct 2017 01:37:05 +0000 (01:37 +0000)
Change-Id: I32df21864719fe72b48149549539d0bad455e4c7
Signed-off-by: Hyunjee Kim <hj0426.kim@samsung.com>
src/utils_i18n_timezone.cpp

index df6e10f..5e773ef 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;
 }