From 9efc08f13fcd898f7bc8ced517e1d7e8596ed096 Mon Sep 17 00:00:00 2001 From: Hyunjee Kim Date: Tue, 10 Oct 2017 15:09:10 +0900 Subject: [PATCH] Implement fallback mechanism to set the time zone to default time zone Change-Id: I32df21864719fe72b48149549539d0bad455e4c7 Signed-off-by: Hyunjee Kim --- src/utils_i18n_timezone.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) 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; } -- 2.34.1