From f9158fe336b3d7d974676172b4e3ae65a956179f Mon Sep 17 00:00:00 2001 From: "jk.koo" Date: Fri, 27 Mar 2020 18:41:51 +0900 Subject: [PATCH 1/1] Fixed the error reading timezone incorrectly Change-Id: I7a0d61e4a7068e2385dae96438cb2572c1b1002d Signed-off-by: jk.koo --- common/cal_time.cpp | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/common/cal_time.cpp b/common/cal_time.cpp index 2520006..80e3c91 100644 --- a/common/cal_time.cpp +++ b/common/cal_time.cpp @@ -457,17 +457,44 @@ int _get_dst_savings(char *tzid) UChar utf16_timezone[CAL_STR_SHORT_LEN64] = {0}; u_uastrncpy(utf16_timezone, tzid, sizeof(utf16_timezone)); - UErrorCode status = U_ZERO_ERROR; + UErrorCode err = U_ZERO_ERROR; + + int dst_time = (int)ucal_getDSTSavings(utf16_timezone, &err); + if (err != 0) { + ERR("ucal_getDSTSavings() failed(%d)", err); + dst_time = 0; + } - return ucal_getDSTSavings(utf16_timezone, &status); + return dst_time; } bool cal_time_is_dst_savings(void) { - char buf[128] = {0}; + char buf[256] = {0}; + char *last = NULL; + char *next = NULL; + char *timezone = NULL; + readlink("/opt/etc/localtime", buf, sizeof(buf) - 1); - char *timezone = buf + 20; /* /usr/share/zoneinfo/ */ + do { + last = strrchr(buf, '/'); + if (NULL == last) + break; + + *last = '\0'; + + next = strrchr(buf, '/'); + } while (0); + + if (NULL == last || NULL == next) { + ERR("There is no timezone info"); + return false; + } + + *last = '/'; + timezone = next + 1; + return _get_dst_savings(timezone) == 0 ? false : true; } -- 2.7.4