1 /* 2 * This file is part of the openHiTLS project. 3 * 4 * openHiTLS is licensed under the Mulan PSL v2. 5 * You can use this software according to the terms and conditions of the Mulan PSL v2. 6 * You may obtain a copy of Mulan PSL v2 at: 7 * 8 * http://license.coscl.org.cn/MulanPSL2 9 * 10 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 11 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 12 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 13 * See the Mulan PSL v2 for more details. 14 */ 15 16 #ifndef SAL_TIME_H 17 #define SAL_TIME_H 18 19 #include "hitls_build.h" 20 #ifdef HITLS_BSL_SAL_TIME 21 22 #include <stddef.h> 23 #include <stdint.h> 24 #include <stdbool.h> 25 #include "bsl_sal.h" 26 27 #ifdef __cplusplus 28 extern "C" { 29 #endif 30 31 #define BSL_TIME_CMP_ERROR 0U /* The comparison between two dates is incorrect. */ 32 #define BSL_TIME_CMP_EQUAL 1U /* The two dates are the same. */ 33 #define BSL_TIME_DATE_BEFORE 2U /* The first date is earlier than the second date */ 34 #define BSL_TIME_DATE_AFTER 3U /* The first date is later than the second date. */ 35 36 #define BSL_TIME_YEAR_START 1900U 37 #define BSL_TIME_SYSTEM_EPOCH_YEAR 1970U 38 #define BSL_TIME_DAY_PER_NONLEAP_YEAR 365U 39 40 #define BSL_TIME_BIG_MONTH_DAY 31U 41 #define BSL_TIME_SMALL_MONTH_DAY 30U 42 #define BSL_TIME_LEAP_FEBRUARY_DAY 29U 43 #define BSL_TIME_NOLEAP_FEBRUARY_DAY 28U 44 45 #define BSL_MONTH_JAN 1U /* January */ 46 #define BSL_MONTH_FEB 2U /* February */ 47 #define BSL_MONTH_MAR 3U /* March */ 48 #define BSL_MONTH_APR 4U /* April */ 49 #define BSL_MONTH_MAY 5U /* May */ 50 #define BSL_MONTH_JUN 6U /* June */ 51 #define BSL_MONTH_JUL 7U /* July */ 52 #define BSL_MONTH_AUG 8U /* August */ 53 #define BSL_MONTH_SEM 9U /* September */ 54 #define BSL_MONTH_OCT 10U /* October */ 55 #define BSL_MONTH_NOV 11U /* November */ 56 #define BSL_MONTH_DEC 12U /* December */ 57 58 #define BSL_TIME_TICKS_PER_SECOND_DEFAULT 100U 59 #define BSL_SECOND_TRANSFER_RATIO 1000U /* conversion ratio of microseconds -> milliseconds -> seconds */ 60 61 #define BSL_UTCTIME_MAX 2005949145599L /* UTC time corresponding to December 31, 65535 23:59:59 */ 62 63 bool BSL_IsLeapYear(uint32_t year); 64 65 /** 66 * @brief Obtain the date in string format. 67 * @param dateTime [IN] Pointer to the date structure to be converted into a string. 68 * @param timeStr [OUT] Pointer to the date string buffer. 69 * @param len [IN] Date string buffer length, which must be greater than 26. 70 * @return BSL_SUCCESS is successfully executed. 71 * BSL_INTERNAL_EXCEPTION Execution Failure 72 */ 73 uint32_t BSL_DateToStrConvert(const BSL_TIME *dateTime, char *timeStr, size_t len); 74 75 /** 76 * @brief Add the time. 77 * @param date [IN] 78 * @param us [IN] 79 * @return BSL_SUCCESS is successfully executed. 80 * For other failures, see BSL_SAL_DateToUtcTimeConvert and BSL_SAL_UtcTimeToDateConvert. 81 */ 82 uint32_t BSL_DateTimeAddUs(BSL_TIME *dateR, const BSL_TIME *dateA, uint32_t us); 83 84 /** 85 * @brief Check whether the time format is correct. 86 * @param dateTime [IN] Time to be checked 87 * @return true The time format is correct. 88 * false incorrect 89 */ 90 bool BSL_DateTimeCheck(const BSL_TIME *dateTime); 91 92 void BSL_SysTimeFuncUnReg(void); 93 94 #ifdef __cplusplus 95 } 96 #endif 97 98 #endif /* HITLS_BSL_SAL_TIME */ 99 100 #endif // SAL_TIME_H 101