[Bug] setting > date and time: modify function get_gmt_offset to format the time .
authorJing Yigang <yigang.jing@samsung.com>
Tue, 28 Aug 2012 03:20:31 +0000 (11:20 +0800)
committerJing Yigang <yigang.jing@samsung.com>
Tue, 28 Aug 2012 03:20:31 +0000 (11:20 +0800)
Change-Id: I7b90328649bd50c88bfacc50aae0218f63895d9d

setting-time/src/setting-time-main.c

index e147b93..9acb078 100755 (executable)
@@ -42,7 +42,7 @@
 static UChar *uastrcpy(const char *chars);
 static void ICU_set_timezone(const char *timezone);
 static int get_timezone_isdst(int* isdst);
-static void get_gmt_offset(char* str_buf);
+static void get_gmt_offset(char *str_buf, int size);
 
 static char* get_timezone_str();
 static char* get_city_name_result();
@@ -579,9 +579,8 @@ static int setting_time_main_create(void *cb)
                // don't use hard coded value
                // get value from current timezone
 
-               char str_buf[4];
-               get_gmt_offset(str_buf);
-               str_buf[3] = '\0';
+               char str_buf[GMT_BUF_SIZE] = {0, };
+               get_gmt_offset(str_buf, GMT_BUF_SIZE);
 
                char* timezone_str = get_timezone_str();
 
@@ -875,26 +874,7 @@ static int __setting_set_city_tzone(const char* pTZPath)
        char* pStr = strdup(pTZPath);
 
        // 2. timezone string +/-<n> ex. +9, -1
-       time_t t = time(0);     // get unix time. sec.
-
-       struct tm* data;
-       data = localtime(&t);           // save time as structure.
-       retv_if(!data, FALSE);
-       data->tm_isdst = 0;                     // summer time, not applied.
-       time_t a = mktime(data);
-
-       data = gmtime(&a);
-       data->tm_isdst = 0;                     // summer time, not applied.
-       time_t b = mktime(data);
-
-       int gmtoffset_hour = (a-b)/3600;        // result : hour.
-       int gmtoffset_min = ((a-b)%3600)/60;    // result : min.
-       if(gmtoffset_min != 0)
-               gmtoffset_min = 30;
-
-       snprintf(szTimezone, GMT_BUF_SIZE, "%+d:%u", gmtoffset_hour, gmtoffset_min);
-
-       SETTING_TRACE("szTimezone is of a valid format: GMT: %s", szTimezone);
+       get_gmt_offset(szTimezone, GMT_BUF_SIZE);
 
        int ret = vconf_set_str(VCONFKEY_SETAPPL_TIMEZONE_INT, szTimezone);
        if (ret == -1) {
@@ -1397,19 +1377,29 @@ static void setting_time_main_controlbar_lbtn_label_set(
  *
  * char outstr2[4];
  */
-static void get_gmt_offset(char* str_buf)
+static void get_gmt_offset(char *str_buf, int size)
 {
-       struct tm* ts;
-       time_t ctime = time(NULL);
-       ts = localtime(&ctime);
+       // timezone string +/-<n> ex. +9, -1
+       time_t t = time(0);     // get unix time. sec.
+
+       struct tm* data;
+       data = localtime(&t);           // save time as structure.
+       retv_if(!data, FALSE);
+       data->tm_isdst = 0;                     // summer time, not applied.
+       time_t a = mktime(data);
 
-       char outstr[256];
-       if (strftime(outstr, sizeof(outstr), "%z", ts) == 0) {
-                       fprintf(stderr, "strftime returned 0");
+       data = gmtime(&a);
+       data->tm_isdst = 0;                     // summer time, not applied.
+       time_t b = mktime(data);
+
+       int gmtoffset_hour = (a-b)/3600;        // result : hour.
+       int gmtoffset_min = ((a-b)%3600)/60;    // result : min.
+       if(gmtoffset_min != 0) {
+               gmtoffset_min = 30;
        }
-       printf("Result string is \"%s\"\n", outstr);
-       strncpy(str_buf, outstr, 3);
-       str_buf[3] = '\0';
+       
+       snprintf(str_buf, size, "%+d:%02u", gmtoffset_hour, gmtoffset_min);
+       SETTING_TRACE("szTimezone is of a valid format: GMT: %s", str_buf);
 }