Fixed the error reading timezone incorrectly 58/229058/1
authorjk.koo <jk.koo@samsung.com>
Fri, 27 Mar 2020 09:41:51 +0000 (18:41 +0900)
committerjk.koo <jk.koo@samsung.com>
Fri, 27 Mar 2020 10:13:48 +0000 (19:13 +0900)
Change-Id: I7a0d61e4a7068e2385dae96438cb2572c1b1002d
Signed-off-by: jk.koo <jk.koo@samsung.com>
common/cal_time.cpp

index 2520006..80e3c91 100644 (file)
@@ -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;
 }