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();
// 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();
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) {
*
* 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);
}