Index: funcs/func_strings.c =================================================================== --- funcs/func_strings.c (revision 8111) +++ funcs/func_strings.c (working copy) @@ -194,6 +194,54 @@ .read = acf_strftime, }; +static char *acf_strptime(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) +{ + char *format, *datetime, *timezone = NULL; + struct tm time; + + memset(&time,0,sizeof(struct tm)); + + buf[0] = '\0'; + + if (!data) { + ast_log(LOG_ERROR, "Asterisk function STRPTIME() requires an argument.\n"); + return buf; + } + + format = ast_strdupa(data); + if (!format) { + ast_log(LOG_ERROR, "Out of memory\n"); + return buf; + } + + datetime = strsep(&format, "|"); + + if (ast_strlen_zero(format) ) { + ast_log(LOG_ERROR, "No format supplied to STRPTIME()"); + return buf; + } + + if (!strptime(datetime, format, &time)) { + ast_log(LOG_WARNING, "C function strftime() output nothing?!!\n"); + } else { + sprintf(buf, "%d", (unsigned int)mktime(&time)); + } + + buf[len - 1] = '\0'; + + return buf; +} + +#ifndef BUILTIN_FUNC +static +#endif +struct ast_custom_function strptime_function = { + .name = "STRPTIME", + .synopsis = "Returns the epoch of the arbitrary date/time string structured as described in the format.", + .syntax = "STRPTIME(|)", + .read = acf_strptime, +}; + static char *function_eval(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) { memset(buf, 0, len);