From: Tomasz Bocheński Date: Fri, 16 Mar 2018 12:30:46 +0000 (+0100) Subject: [base-utils][ACR-1202][DateInterval] Module implementation X-Git-Tag: accepted/tizen/unified/20180426.062448^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=85ea79fe0c815643af58014247e0e8478df81bf2;p=platform%2Fcore%2Fapi%2Fbase-utils.git [base-utils][ACR-1202][DateInterval] Module implementation Change-Id: I9cc18fe990e8f594c89b51425e797c168991ae4d Signed-off-by: Tomasz Bocheński --- diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3c8df4e..5e9cae8 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -43,6 +43,7 @@ SET(BASEUTILS_SRCS utils_i18n_plural_rules.cpp utils_i18n_plural_format.cpp utils_i18n_immutable_idx.cpp + utils_i18n_date_interval.cpp ) ADD_LIBRARY(${target_name} SHARED ${BASEUTILS_SRCS} @@ -93,5 +94,6 @@ INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${INC_DIR}/utils_i18n_uchar_iter.h DES INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${INC_DIR}/utils_i18n_plural_rules.h DESTINATION ${INCLUDE_INSTALL_DIR}/base) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${INC_DIR}/utils_i18n_plural_format.h DESTINATION ${INCLUDE_INSTALL_DIR}/base) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${INC_DIR}/utils_i18n_immutable_idx.h DESTINATION ${INCLUDE_INSTALL_DIR}/base) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${INC_DIR}/utils_i18n_date_interval.h DESTINATION ${INCLUDE_INSTALL_DIR}/base) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${INC_DIR}/utils_i18n.h DESTINATION ${INCLUDE_INSTALL_DIR}/base) INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${pc_name}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) diff --git a/src/include/utils_i18n.h b/src/include/utils_i18n.h index 54184fb..28ca174 100644 --- a/src/include/utils_i18n.h +++ b/src/include/utils_i18n.h @@ -48,6 +48,7 @@ #include #include #include +#include /** * @file utils_i18n.h @@ -89,6 +90,7 @@ extern "C" { * - plural rules * - plural format * - immutable_idx + * - date interval * * This module provides flexible generation of number or date format patterns and helps you format and parse dates/number for any locale. * The i18n module provides various features based on data from ICU. The following table shows the version of ICU used in each Tizen platform. @@ -235,6 +237,10 @@ extern "C" { * @ref CAPI_BASE_UTILS_I18N_IMMUTABLE_IDX_MODULE * The Immutable_idx is immutable, thread-safe version of Alpha_idx. * + * + * @ref CAPI_BASE_UTILS_I18N_DATE_INTERVAL_MODULE + * Date interval represents a date interval. + * * * * @section CAPI_BASE_UTILS_I18N_MODULE_MAPPING_TABLE Mapping Table @@ -3916,6 +3922,36 @@ extern "C" { * #i18n_immutable_idx_get_bucket_label_type * getLabelType * + * + * @ref CAPI_BASE_UTILS_I18N_DATE_INTERVAL_MODULE + * #i18n_date_interval_create + * DateInterval + * + * + * @ref CAPI_BASE_UTILS_I18N_DATE_INTERVAL_MODULE + * #i18n_date_interval_destroy + * ~DateInterval + * + * + * @ref CAPI_BASE_UTILS_I18N_DATE_INTERVAL_MODULE + * #i18n_date_interval_clone + * clone + * + * + * @ref CAPI_BASE_UTILS_I18N_DATE_INTERVAL_MODULE + * #i18n_date_interval_get_from_date + * getFromDate + * + * + * @ref CAPI_BASE_UTILS_I18N_DATE_INTERVAL_MODULE + * #i18n_date_interval_get_to_date + * getToDate + * + * + * @ref CAPI_BASE_UTILS_I18N_DATE_INTERVAL_MODULE + * #i18n_date_interval_equals + * operator== + * * */ diff --git a/src/include/utils_i18n_date_interval.h b/src/include/utils_i18n_date_interval.h new file mode 100644 index 0000000..9d4d580 --- /dev/null +++ b/src/include/utils_i18n_date_interval.h @@ -0,0 +1,143 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __UTILS_I18N_DATE_INTERVAL_H__ +#define __UTILS_I18N_DATE_INTERVAL_H__ + +#include + +/** + * @file utils_i18n_date_interval.h + * @version 0.1 + * @brief utils_i18n_date_interval + */ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @ingroup CAPI_BASE_UTILS_I18N_MODULE + * @defgroup CAPI_BASE_UTILS_I18N_DATE_INTERVAL_MODULE Date Interval + * @brief Date Interval represents a date interval. + * @section CAPI_BASE_UTILS_I18N_DATE_INTERVAL_MODULE_HEADER Required Header + * \#include + * + * @section CAPI_BASE_UTILS_I18N_DATE_INTERVAL_MODULE_OVERVIEW Overview + * @details The module represents a date interval. + */ + +/** + * @addtogroup CAPI_BASE_UTILS_I18N_DATE_INTERVAL_MODULE + * @{ + */ + +/** + * @brief Creates a date interval object. + * @since_tizen 5.0 + * @remarks The created object should be released by the caller with the + * i18n_date_interval_destroy() function. + * + * @param[in] from_date The start date of the date interval + * @param[in] to_date The end date of the date interval + * @param[out] date_interval The created date interval object + * + * @return @c 0 on success, otherwise a negative error value + * @retval #I18N_ERROR_NONE Successful + * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter + * @retval #I18N_ERROR_OUT_OF_MEMORY Out of memory + */ +int i18n_date_interval_create(i18n_udate from_date, i18n_udate to_date, i18n_date_interval_h *date_interval); + +/** + * @brief Destroys the date interval object. + * @since_tizen 5.0 + * + * @param[in] date_interval The date interval to be destroyed + * + * @return @c 0 on success, otherwise a negative error value + * @retval #I18N_ERROR_NONE Successful + * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter + */ +int i18n_date_interval_destroy(i18n_date_interval_h date_interval); + +/** + * @brief Clones the date interval object. + * @since_tizen 5.0 + * @remarks The cloned object should be released by the caller with the + * i18n_date_interval_destroy() function. + * + * @param[in] date_interval The date interval to be cloned + * @param[out] clone The clone of the given @a date_interval object + * + * @return @c 0 on success, otherwise a negative error value + * @retval #I18N_ERROR_NONE Successful + * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter + * @retval #I18N_ERROR_OUT_OF_MEMORY Out of memory + */ +int i18n_date_interval_clone(i18n_date_interval_h date_interval, i18n_date_interval_h *clone); + +/** + * @brief Gets the 'from date' from a given date interval object. + * @since_tizen 5.0 + * + * @param[in] date_interval The date interval object + * @param[out] from_date The 'from date' value + * + * @return @c 0 on success, otherwise a negative error value + * @retval #I18N_ERROR_NONE Successful + * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter + */ +int i18n_date_interval_get_from_date(i18n_date_interval_h date_interval, i18n_udate *from_date); + +/** + * @brief Gets the 'to date' from a given date interval object. + * @since_tizen 5.0 + * + * @param[in] date_interval The date interval object + * @param[out] to_date The 'to date' value + * + * @return @c 0 on success, otherwise a negative error value + * @retval #I18N_ERROR_NONE Successful + * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter + */ +int i18n_date_interval_get_to_date(i18n_date_interval_h date_interval, i18n_udate *to_date); + +/** + * @brief Compares two date interval objects. + * @since_tizen 5.0 + * + * @param[in] date_interval_1 The first date interval object + * @param[in] date_interval_2 The second date interval object + * @param[out] equals A flag set to @c true if given objects are equal, + * or @c false otherwise. + * + * @return @c 0 on success, otherwise a negative error value + * @retval #I18N_ERROR_NONE Successful + * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter + */ +int i18n_date_interval_equals(i18n_date_interval_h date_interval_1, i18n_date_interval_h date_interval_2, + i18n_ubool *equals); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* __UTILS_I18N_DATE_INTERVAL_H__ */ diff --git a/src/include/utils_i18n_types.h b/src/include/utils_i18n_types.h index e74f9cb..c8ace19 100644 --- a/src/include/utils_i18n_types.h +++ b/src/include/utils_i18n_types.h @@ -4402,6 +4402,22 @@ typedef void *i18n_immutable_idx_h; */ /** +* @addtogroup CAPI_BASE_UTILS_I18N_DATE_INTERVAL_MODULE +* @{ +*/ + +/** + * @brief An #i18n_date_interval_h handle. + * @details Use i18n_date_interval_* functions to operate on #i18n_date_interval_h objects. + * @since_tizen 5.0 + */ +typedef void *i18n_date_interval_h; + +/** + * @} + */ + +/** * @brief This value is intended for sentinel values for APIs that (take or) return * single code points (#i18n_uchar32). * @details It is outside of the Unicode code point range 0..0x10ffff. For example, diff --git a/src/utils_i18n_date_interval.cpp b/src/utils_i18n_date_interval.cpp new file mode 100644 index 0000000..0b18be1 --- /dev/null +++ b/src/utils_i18n_date_interval.cpp @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include + +int i18n_date_interval_create(i18n_udate from_date, i18n_udate to_date, i18n_date_interval_h *date_interval) +{ + retv_if(date_interval == NULL, I18N_ERROR_INVALID_PARAMETER); + + *date_interval = new DateInterval(from_date, to_date); + retv_if(*date_interval == NULL, I18N_ERROR_OUT_OF_MEMORY); + + return I18N_ERROR_NONE; +} + +int i18n_date_interval_destroy(i18n_date_interval_h date_interval) +{ + retv_if(date_interval == NULL, I18N_ERROR_INVALID_PARAMETER); + + delete ((DateInterval *) date_interval); + + return I18N_ERROR_NONE; +} + +int i18n_date_interval_clone(i18n_date_interval_h date_interval, i18n_date_interval_h *clone) +{ + retv_if(date_interval == NULL, I18N_ERROR_INVALID_PARAMETER); + retv_if(clone == NULL, I18N_ERROR_INVALID_PARAMETER); + + *clone = ((DateInterval *) date_interval)->clone(); + + return I18N_ERROR_NONE; +} + +int i18n_date_interval_get_from_date(i18n_date_interval_h date_interval, i18n_udate *from_date) +{ + retv_if(date_interval == NULL, I18N_ERROR_INVALID_PARAMETER); + retv_if(from_date == NULL, I18N_ERROR_INVALID_PARAMETER); + + *from_date = ((DateInterval *) date_interval)->getFromDate(); + + return I18N_ERROR_NONE; +} + +int i18n_date_interval_get_to_date(i18n_date_interval_h date_interval, i18n_udate *to_date) +{ + retv_if(date_interval == NULL, I18N_ERROR_INVALID_PARAMETER); + retv_if(to_date == NULL, I18N_ERROR_INVALID_PARAMETER); + + *to_date = ((DateInterval *) date_interval)->getToDate(); + + return I18N_ERROR_NONE; +} + +int i18n_date_interval_equals(i18n_date_interval_h date_interval_1, i18n_date_interval_h date_interval_2, + i18n_ubool *equals) +{ + retv_if(date_interval_1 == NULL, I18N_ERROR_INVALID_PARAMETER); + retv_if(date_interval_2 == NULL, I18N_ERROR_INVALID_PARAMETER); + retv_if(equals == NULL, I18N_ERROR_INVALID_PARAMETER); + + *equals = (*((DateInterval *) date_interval_1)) == (*((DateInterval *) date_interval_2)); + + return I18N_ERROR_NONE; +}