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 "worldclock_fwk_icu.h"
19 #include "worldclock_types.h"
20 #include "worldclock_dlog.h"
22 //char *data_pattern[4] =
29 //char *data_pattern_without_year[4] =
36 char *time_pattern[2] = {
42 static int __get_pattern_time(char *pattern, int size,
43 CLK_TIME_FORMAT timeStyle)
45 retvm_if(!pattern, FAILED, "pattern null");
46 retvm_if(size <= 0, FAILED, "size<=0");
47 snprintf(pattern, size, "%s", time_pattern[timeStyle]);
52 static int __get_pattern_time_and_date(char *pattern, int size,
53 CLK_TIME_FORMAT timeStyle,
54 CLK_DATE_FORMAT dateStyle)
56 retvm_if(!pattern, FAILED, "pattern null");
57 retvm_if(size <= 0, FAILED, "size<=0");
58 snprintf(pattern, size, "%s\t%s", "yMMMd", time_pattern[timeStyle]);
63 char *worldclock_icu_get_time_str(time_t input_time, const char *timezone)
65 static char string_icu_time[BUF_SIZE] = { 0 };
66 char pattern[MAX_PATTERN_LENGHT] = { 0 };
67 CLK_TIME_FORMAT time_format;
68 time_format = clk_fwk_icu_time_format_get();
69 __get_pattern_time(pattern, MAX_PATTERN_LENGHT, time_format);
70 //CLK_INFO_PURPLE("pattern=%s",pattern);
71 clk_fwk_icu_get_data(input_time, string_icu_time, BUF_SIZE, NULL,
72 pattern, MAX_PATTERN_LENGHT, timezone);
73 // splice time string to result string
74 return string_icu_time;
78 char *worldclock_icu_get_date_str(time_t input_time, const char *timezone)
80 static char string_icu_date[BUF_SIZE] = { 0 };
81 // get date string to result string by icu module
82 clk_fwk_icu_get_data(input_time, string_icu_date, BUF_SIZE, NULL,
83 "MMMd", MAX_PATTERN_LENGHT, timezone);
84 return string_icu_date;
88 char *worldclock_icu_get_time_date_str(time_t input_time, const char *timezone)
90 static char string_icu_time_and_date[BUF_SIZE] = { 0 };
91 char pattern[MAX_PATTERN_LENGHT] = { 0 };
92 __get_pattern_time_and_date(pattern, MAX_PATTERN_LENGHT,
93 clk_fwk_icu_time_format_get(),
94 clk_fwk_icu_date_format_get());
95 clk_fwk_icu_get_data(input_time, string_icu_time_and_date, BUF_SIZE,
96 NULL, pattern, MAX_PATTERN_LENGHT, timezone);
97 // splice date string & time string to result string
98 return string_icu_time_and_date;
101 /*BEG: Gong Xingsheng<x536.gong@samsung.com> add in Mon Nov 21 01:04:37 PST 2011
102 * this function is used to get worldclock_time_s type date
103 * from icu, get the current hour, minute, second and current am/pm
105 worldclock_time_s *worldclock_icu_get_time_int(time_t input_time,
106 const char *timezone)
108 static worldclock_time_s worldclock_time;
109 char string[BUF_SIZE] = { 0 };
112 clk_fwk_icu_get_data(input_time, string, BUF_SIZE,
113 NULL, "HHmmss", MAX_PATTERN_LENGHT, timezone);
116 worldclock_time.hour = atoi(tmp);
120 worldclock_time.min = atoi(tmp);
124 worldclock_time.sec = atoi(tmp);
126 CLK_TIME_FORMAT time_format = clk_fwk_icu_time_format_get();
127 worldclock_time.bAm =
128 IS_EQUAL(time_format, CLK_TIME_FORMAT_12HOUR) ? true : false;
129 return &worldclock_time;
132 /*END: Gong Xingsheng<x536.gong@samsung.com> add in Mon Nov 21 01:04:37 PST 2011 */
134 /*BEG: Gong Xingsheng<x536.gong@samsung.com> add in Mon Nov 21 01:04:37 PST 2011
135 * this function is used to get dst value from tz_path by icu
137 int worldclock_icu_dst_get(const char *tz_path)
139 retv_if(!tz_path, -1);
141 UErrorCode status = U_ZERO_ERROR;
142 UChar UPath[BUF_SIZE_64] = { 0 };
144 u_uastrcpy(UPath, tz_path);
146 dst = ucal_getDSTSavings(UPath, &status);
147 retvm_if(U_FAILURE(status), -1, "error value is %s",
148 u_errorName(status));
149 dst = dst / 60 / 60 / 1000;
153 /*END: Gong Xingsheng<x536.gong@samsung.com> add in Mon Nov 21 01:04:37 PST 2011 */