2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.tizenopensource.org/license
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #define __CLK_FWK_ICU_C__
18 #include "clock_fwk_icu.h"
20 #include <unicode/udatpg.h>
21 #include <unicode/ucnv.h>
24 CLK_DATE_FORMAT clk_fwk_icu_date_format_get()
26 CLK_DATE_FORMAT dateStyle = CLK_DATE_FORMAT_DD_MM_YYYY;
29 ret = vconf_get_int(VCONFKEY_SETAPPL_DATE_FORMAT_INT, &value);
31 value = SETTING_DATE_FORMAT_DD_MM_YYYY;
34 case SETTING_DATE_FORMAT_DD_MM_YYYY:
35 dateStyle = CLK_DATE_FORMAT_DD_MM_YYYY;
37 case SETTING_DATE_FORMAT_MM_DD_YYYY:
38 dateStyle = CLK_DATE_FORMAT_MM_DD_YYYY;
40 case SETTING_DATE_FORMAT_YYYY_MM_DD:
41 dateStyle = CLK_DATE_FORMAT_YYYY_MM_DD;
43 case SETTING_DATE_FORMAT_YYYY_DD_MM:
44 dateStyle = CLK_DATE_FORMAT_YYYY_DD_MM;
53 CLK_TIME_FORMAT clk_fwk_icu_time_format_get()
55 CLK_TIME_FORMAT time_format = CLK_TIME_FORMAT_12HOUR;
58 ret = vconf_get_int(VCONFKEY_REGIONFORMAT_TIME1224, &value);
59 // if failed, set default time format
61 value = VCONFKEY_TIME_FORMAT_12;
64 case VCONFKEY_TIME_FORMAT_12:
65 time_format = CLK_TIME_FORMAT_12HOUR;
67 case VCONFKEY_TIME_FORMAT_24:
68 time_format = CLK_TIME_FORMAT_24HOUR;
77 int clk_fwk_icu_get_data(time_t intime, char *dstStr, int dstStr_num, char *loc,
78 char *pattern, int pattern_num, const char *timezone)
82 UDateFormat *date_fmt = NULL;
83 UErrorCode status = U_ZERO_ERROR;
84 const char *locale = timezone;
88 UChar bestPattern[MAX_PATTERN_LENGHT] = { 0, };
89 int32_t bestPatternCapacity;
90 int32_t bestPatternLength;
91 UDateTimePatternGenerator *generator = NULL;
94 CLK_RETVM_IF(!dstStr, FAILED, "str NULL");
95 CLK_RETVM_IF(dstStr_num <= 0, FAILED, "dstStr_num<=0");
96 CLK_RETVM_IF(!pattern, FAILED, "pattern NULL");
97 CLK_RETVM_IF(pattern_num <= 0, FAILED, "pattern_num<=0");
99 //date = ucal_getNow();
100 tmpdate = (double)1000 *intime;
101 uloc_setDefault((const char *)__secure_getenv("LC_TIME"), &status);
102 locale = loc ? loc : uloc_getDefault();
103 CLK_RETVM_IF(!locale, FAILED, "locale NULL");
105 UChar timezoneID[MAX_TIMEZONE_LENGHT] = { 0 };
107 u_uastrncpy(timezoneID, timezone, MAX_TIMEZONE_LENGHT);
110 UChar upattern[MAX_PATTERN_LENGHT] = { 0 };
111 u_uastrncpy(upattern, pattern, MAX_PATTERN_LENGHT);
112 // generate best pattern for locale region
113 generator = udatpg_open(locale, &status);
114 bestPatternCapacity =
115 (int32_t) (sizeof(bestPattern) / sizeof((bestPattern)[0]));
117 udatpg_getBestPattern(generator, upattern, u_strlen(upattern),
118 bestPattern, bestPatternCapacity, &status);
122 udat_open(UDAT_IGNORE, UDAT_DEFAULT, locale, timezoneID, -1,
123 bestPattern, bestPatternLength, &status);
126 udat_open(UDAT_IGNORE, UDAT_DEFAULT, locale, NULL, -1,
127 bestPattern, bestPatternLength, &status);
129 CLK_RETVM_IF(!date_fmt, FAILED, "udat_open failed");
131 tmplen = udat_format(date_fmt, tmpdate, NULL, tmplen, NULL, &status);
132 CLK_RETVM_IF(IS_EQUAL(0, tmplen), FAILED, "tmplen=0");
134 if (IS_EQUAL(status, U_BUFFER_OVERFLOW_ERROR)) {
135 status = U_ZERO_ERROR;
136 tmpstr = (UChar *) malloc(sizeof(UChar) * (tmplen + 1));
137 CLK_RETVM_IF(NULL_CHECK(tmpstr), FAILED, "malloc failed");
139 udat_format(date_fmt, tmpdate, tmpstr, tmplen + 1, NULL,
143 dstStr = u_austrncpy(dstStr, tmpstr, dstStr_num);
144 CLK_INFO_PURPLE("result:%s", dstStr);
148 udatpg_close(generator);
151 udat_close(date_fmt);
158 int clk_timezone_get(char *dst, size_t number)
160 retv_if(!dst || number < 1, FAILED);
161 UChar timezoneID[MAX_TIMEZONE_LENGHT] = { 0 };
162 UErrorCode status = U_ZERO_ERROR;
163 ucal_getDefaultTimeZone(timezoneID, MAX_TIMEZONE_LENGHT, &status);
164 retv_if(status != SUCCESS, FAILED);
166 dst = u_austrncpy(dst, timezoneID, number);
167 CLK_INFO_PURPLE("default timezone is %s: ", dst);
171 void clk_timezone_update()
173 UErrorCode status = U_ZERO_ERROR;
174 UChar uOlsonID[BUF_SIZE_64] = { 0 };
176 char *timezone = vconf_get_str(VCONFKEY_SETAPPL_TIMEZONE_ID);
178 CLK_INFO_PURPLE("current timezone is : %s", timezone);
179 u_uastrcpy(uOlsonID, timezone);
180 ucal_setDefaultTimeZone(uOlsonID, &status);
183 retm_if(U_FAILURE(status), "error value is %s", u_errorName(status));