From e16e0f5d4f940c6ba24037f4e3c6e7222b8210fc Mon Sep 17 00:00:00 2001 From: yuqing Date: Fri, 11 Nov 2016 15:14:51 +0800 Subject: [PATCH] add function get_time_item_from_str --- HISTORY | 3 ++- src/shared_func.c | 11 ++++++++++- src/shared_func.h | 16 +++++++++++++++- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/HISTORY b/HISTORY index dfd11a9..297eb44 100644 --- a/HISTORY +++ b/HISTORY @@ -1,6 +1,7 @@ -Version 1.31 2016-11-10 +Version 1.31 2016-11-11 * move SET_SOCKOPT_NOSIGPIPE from sockopt.c to sockopt.h + * add function get_time_item_from_str Version 1.30 2016-10-31 * modify php-fastcommon/test.php diff --git a/src/shared_func.c b/src/shared_func.c index 3f8e0d6..3c9af55 100644 --- a/src/shared_func.c +++ b/src/shared_func.c @@ -1964,16 +1964,25 @@ int get_time_item_from_conf(IniContext *pIniContext, \ const byte default_hour, const byte default_minute) { char *pValue; + pValue = iniGetStrValue(NULL, item_name, pIniContext); + return get_time_item_from_str(pValue, item_name, pTimeInfo, + default_hour, default_minute); +} + +int get_time_item_from_str(const char *pValue, const char *item_name, + TimeInfo *pTimeInfo, const byte default_hour, + const byte default_minute) +{ int hour; int minute; int second; int count; - pValue = iniGetStrValue(NULL, item_name, pIniContext); if (pValue == NULL) { pTimeInfo->hour = default_hour; pTimeInfo->minute = default_minute; + pTimeInfo->second = 0; return 0; } diff --git a/src/shared_func.h b/src/shared_func.h index ba3a02f..a8a2583 100644 --- a/src/shared_func.h +++ b/src/shared_func.h @@ -370,7 +370,7 @@ int load_allow_hosts(IniContext *pIniContext, \ /** get time item from config context * parameters: * pIniContext: the config context - * item_name: item name in config file, time format: hour:minute, such as 15:25 + * item_name: item name in config file, time format as hour:minute, such as 15:25 * pTimeInfo: store time info * default_hour: default hour value * default_minute: default minute value @@ -380,6 +380,20 @@ int get_time_item_from_conf(IniContext *pIniContext, \ const char *item_name, TimeInfo *pTimeInfo, \ const byte default_hour, const byte default_minute); + +/** get time item from string + * parameters: + * pValue: the time string, format as hour:minute, such as 15:25 + * item_name: item name in config file + * pTimeInfo: store time info + * default_hour: default hour value + * default_minute: default minute value + * return: error no , 0 success, != 0 fail +*/ +int get_time_item_from_str(const char *pValue, const char *item_name, + TimeInfo *pTimeInfo, const byte default_hour, + const byte default_minute); + /** trim path tail char / * parameters: * filePath: the file path to chop