From: Hyunjee Kim Date: Tue, 10 Oct 2017 06:09:10 +0000 (+0900) Subject: Implement fallback mechanism to set the time zone to default time zone X-Git-Tag: submit/tizen/20171018.014319^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1193a2d17f340033d08955fa639f7ab75d9cdd2e;p=platform%2Fcore%2Fapi%2Fbase-utils.git Implement fallback mechanism to set the time zone to default time zone Change-Id: I32df21864719fe72b48149549539d0bad455e4c7 Signed-off-by: Hyunjee Kim --- diff --git a/src/utils_i18n_timezone.cpp b/src/utils_i18n_timezone.cpp index df6e10f..5e773ef 100755 --- a/src/utils_i18n_timezone.cpp +++ b/src/utils_i18n_timezone.cpp @@ -22,6 +22,7 @@ #include #include +#include #include #include #include @@ -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; }