2 * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
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 #include <unicode/udat.h>
18 #include <utils_i18n_udate.h>
19 #include <utils_i18n_private.h>
21 int i18n_udate_create ( i18n_udate_format_style_e time_style, i18n_udate_format_style_e date_style, const char *locale, const i18n_uchar *tz_id, int32_t tz_id_len, const i18n_uchar *pattern, int32_t pattern_len, i18n_udate_format_h *format )
23 retv_if( format == NULL, I18N_ERROR_INVALID_PARAMETER );
25 UErrorCode icu_error = U_ZERO_ERROR;
26 *format = udat_open(time_style, date_style, locale, tz_id, tz_id_len, pattern, pattern_len, &icu_error);
27 ERR("Error code : %d", icu_error);
29 i18n_error_code_e i18n_error;
30 ERR_MAPPING(icu_error, i18n_error);
34 int i18n_udate_destroy ( i18n_udate_format_h format )
36 retv_if( format == NULL, I18N_ERROR_INVALID_PARAMETER );
39 return I18N_ERROR_NONE;
42 int i18n_udate_format_date ( const i18n_udate_format_h format, i18n_udate date_to_format, i18n_uchar *result, int32_t result_len, i18n_ufield_position_h pos, int32_t *buf_size_needed )
44 retv_if( format == NULL || buf_size_needed == NULL, I18N_ERROR_INVALID_PARAMETER );
46 UErrorCode icu_error = U_ZERO_ERROR;
47 *buf_size_needed = udat_format(format, date_to_format, result, result_len, (UFieldPosition*)pos, &icu_error);
48 ERR("Error code : %d", icu_error);
50 i18n_error_code_e i18n_error;
51 ERR_MAPPING(icu_error, i18n_error);
56 int i18n_udate_to_calendar_date_field ( i18n_udate_format_field_e field, i18n_ucalendar_date_fields_e *date_field_type )
58 if (date_field_type == NULL)
60 return I18N_ERROR_INVALID_PARAMETER;
64 case I18N_UDATE_FORMAT_TIMEZONE_LOCALIZED_GMT_OFFSET_FIELD:
65 case I18N_UDATE_FORMAT_TIMEZONE_ISO_FIELD:
66 case I18N_UDATE_FORMAT_TIMEZONE_ISO_LOCAL_FIELD:
67 case I18N_UDATE_FORMAT_FIELD_COUNT:
68 ERR("Unsupported field");
69 return I18N_ERROR_INVALID_PARAMETER;
71 *date_field_type = (i18n_ucalendar_date_fields_e)udat_toCalendarDateField(field);
74 return I18N_ERROR_NONE;
77 int i18n_udate_clone ( const i18n_udate_format_h format, i18n_udate_format_h *format_clone )
79 if (format == NULL || format_clone == NULL)
81 return I18N_ERROR_INVALID_PARAMETER;
84 UErrorCode icu_error = U_ZERO_ERROR;
85 *format_clone = (i18n_udate_format_h)udat_clone((const UDateFormat *)format, &icu_error);
86 ERR("Error code : %d", icu_error);
88 i18n_error_code_e i18n_error;
89 ERR_MAPPING(icu_error, i18n_error);
93 int i18n_udate_parse ( const i18n_udate_format_h format, const i18n_uchar *text, int32_t text_length, int32_t *parse_pos, i18n_udate *parsed_date )
95 if (format == NULL || text == NULL || parsed_date == NULL)
97 return I18N_ERROR_INVALID_PARAMETER;
100 UErrorCode icu_error = U_ZERO_ERROR;
101 *parsed_date = udat_parse((const UDateFormat *)format, text, text_length, parse_pos, &icu_error);
102 ERR("Error code : %d", icu_error);
104 i18n_error_code_e i18n_error;
105 ERR_MAPPING(icu_error, i18n_error);
109 int i18n_udate_parse_calendar (const i18n_udate_format_h format, i18n_ucalendar_h * calendar, const i18n_uchar *text, int32_t text_length, int32_t *parse_pos )
111 if (format == NULL || calendar == NULL || text == NULL || text_length < -1)
113 return I18N_ERROR_INVALID_PARAMETER;
116 UErrorCode icu_error = U_ZERO_ERROR;
117 udat_parseCalendar((const UDateFormat *)format, calendar, text, text_length, parse_pos, &icu_error);
118 ERR("Error code : %d", icu_error);
120 i18n_error_code_e i18n_error;
121 ERR_MAPPING(icu_error, i18n_error);
125 i18n_ubool i18n_udate_is_lenient ( const i18n_udate_format_h format )
129 set_last_result(I18N_ERROR_INVALID_PARAMETER);
133 set_last_result(I18N_ERROR_NONE);
134 return udat_isLenient((const UDateFormat *)format);
137 int i18n_udate_set_lenient ( i18n_udate_format_h format, i18n_ubool is_lenient )
141 return I18N_ERROR_INVALID_PARAMETER;
143 udat_setLenient((UDateFormat *)format, is_lenient);
144 return I18N_ERROR_NONE;
147 int i18n_udate_get_calendar ( const i18n_udate_format_h format, i18n_ucalendar_h *calendar)
149 if (format == NULL || calendar == NULL)
151 return I18N_ERROR_INVALID_PARAMETER;
153 *calendar = (i18n_ucalendar_h)udat_getCalendar((const UDateFormat *)format);
155 return I18N_ERROR_NONE;
158 int i18n_udate_set_calendar ( i18n_udate_format_h format, const i18n_ucalendar_h calendar_to_set )
160 if (format == NULL || calendar_to_set == NULL)
162 return I18N_ERROR_INVALID_PARAMETER;
164 udat_setCalendar((UDateFormat *)format, (const UCalendar *)calendar_to_set);
165 return I18N_ERROR_NONE;
168 int i18n_udate_get_number_format ( const i18n_udate_format_h format, i18n_unumber_format_h *number_format )
170 if (format == NULL || number_format == NULL)
172 return I18N_ERROR_INVALID_PARAMETER;
174 set_last_result(I18N_ERROR_NONE);
175 *number_format = (i18n_unumber_format_h)udat_getNumberFormat((const UDateFormat *)format);
176 return I18N_ERROR_NONE;
179 int i18n_udate_set_number_format ( i18n_udate_format_h format, const i18n_unumber_format_h number_format_to_set )
181 if (format == NULL || number_format_to_set == NULL)
183 return I18N_ERROR_INVALID_PARAMETER;
185 udat_setNumberFormat((UDateFormat *)format, (const UNumberFormat *)number_format_to_set);
186 return I18N_ERROR_NONE;
189 const char *i18n_udate_get_available ( int32_t locale_index )
191 if(locale_index < 0) {
192 set_last_result(I18N_ERROR_INVALID_PARAMETER);
195 set_last_result(I18N_ERROR_NONE);
196 return udat_getAvailable(locale_index);
199 int32_t i18n_udate_count_available ( void )
201 set_last_result(I18N_ERROR_NONE);
202 return udat_countAvailable();
205 int i18n_udate_get_2digit_year_start ( const i18n_udate_format_h format, i18n_udate *year )
207 if (format == NULL || year == NULL)
209 return I18N_ERROR_INVALID_PARAMETER;
212 UErrorCode icu_error = U_ZERO_ERROR;
213 *year = (i18n_udate)udat_get2DigitYearStart((const UDateFormat *)format, &icu_error);
214 ERR("Error code : %d", icu_error);
216 i18n_error_code_e i18n_error;
217 ERR_MAPPING(icu_error, i18n_error);
221 int i18n_udate_set_2digit_year_start ( i18n_udate_format_h format, i18n_udate date )
225 return I18N_ERROR_INVALID_PARAMETER;
228 UErrorCode icu_error = U_ZERO_ERROR;
229 udat_set2DigitYearStart((UDateFormat *)format, date, &icu_error);
230 ERR("Error code : %d", icu_error);
232 i18n_error_code_e i18n_error;
233 ERR_MAPPING(icu_error, i18n_error);
237 int32_t i18n_udate_to_pattern ( const i18n_udate_format_h format, i18n_ubool localized, i18n_uchar *result, int32_t result_length )
241 set_last_result(I18N_ERROR_INVALID_PARAMETER);
245 UErrorCode icu_error = U_ZERO_ERROR;
246 int32_t needed_buffer_size = udat_toPattern((const UDateFormat *)format, localized, result, result_length, &icu_error);
247 ERR("Error code : %d", icu_error);
249 i18n_error_code_e i18n_error;
250 ERR_MAPPING(icu_error, i18n_error);
251 set_last_result(i18n_error);
252 return needed_buffer_size;
255 int i18n_udate_apply_pattern ( i18n_udate_format_h format, i18n_ubool localized, const i18n_uchar *pattern, int32_t pattern_length )
259 return I18N_ERROR_INVALID_PARAMETER;
261 udat_applyPattern((UDateFormat *)format, localized, pattern, pattern_length);
262 return I18N_ERROR_NONE;
265 int32_t i18n_udate_get_symbols ( const i18n_udate_format_h format, i18n_udate_format_symbol_type_e type, int32_t symbol_index, i18n_uchar *result, int32_t result_length )
269 set_last_result(I18N_ERROR_INVALID_PARAMETER);
273 UErrorCode icu_error = U_ZERO_ERROR;
274 int32_t needed_buffer_size = udat_getSymbols((const UDateFormat *)format, type, symbol_index, result, result_length, &icu_error);
275 ERR("Error code : %d", icu_error);
277 i18n_error_code_e i18n_error;
278 ERR_MAPPING(icu_error, i18n_error);
279 set_last_result(i18n_error);
280 return needed_buffer_size;
283 int32_t i18n_udate_count_symbols ( const i18n_udate_format_h format, i18n_udate_format_symbol_type_e type )
287 set_last_result(I18N_ERROR_INVALID_PARAMETER);
291 set_last_result(I18N_ERROR_NONE);
292 return udat_countSymbols((const UDateFormat *)format, type);
295 int i18n_udate_set_symbols ( i18n_udate_format_h format, i18n_udate_format_symbol_type_e type, int32_t symbol_index, i18n_uchar *value, int32_t value_length )
297 if (format == NULL || symbol_index < 0)
299 return I18N_ERROR_INVALID_PARAMETER;
302 UErrorCode icu_error = U_ZERO_ERROR;
303 udat_setSymbols((UDateFormat *)format, type, symbol_index, value, value_length, &icu_error);
304 ERR("Error code : %d", icu_error);
306 i18n_error_code_e i18n_error;
307 ERR_MAPPING(icu_error, i18n_error);
311 const char *i18n_udate_get_locale_by_type ( const i18n_udate_format_h format, i18n_ulocale_data_locale_type_e type )
315 set_last_result(I18N_ERROR_INVALID_PARAMETER);
319 UErrorCode icu_error = U_ZERO_ERROR;
320 const char *locale_name = udat_getLocaleByType((const UDateFormat *)format, type, &icu_error);
321 ERR("Error code : %d", icu_error);
323 i18n_error_code_e i18n_error;
324 ERR_MAPPING(icu_error, i18n_error);
325 set_last_result(i18n_error);
329 int i18n_udate_set_context ( i18n_udate_format_h format, i18n_udisplay_context_e value )
333 return I18N_ERROR_INVALID_PARAMETER;
336 UErrorCode icu_error = U_ZERO_ERROR;
337 udat_setContext((UDateFormat *)format, value, &icu_error);
338 ERR("Error code : %d", icu_error);
340 i18n_error_code_e i18n_error;
341 ERR_MAPPING(icu_error, i18n_error);