aboutsummaryrefslogtreecommitdiffstats
path: root/funcs/func_strings.c
diff options
context:
space:
mode:
authortilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2006-01-22 08:09:02 +0000
committertilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2006-01-22 08:09:02 +0000
commit7272fcf49e2f50b63a60a923a296ddebac3c82b1 (patch)
tree36476bc2c5c4b08ff3580c85b29b268385c8b8cd /funcs/func_strings.c
parent238fbe0ad3136ff55766754e7d893095b175f5df (diff)
Bug 6262 - New function STRPTIME
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@8428 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'funcs/func_strings.c')
-rw-r--r--funcs/func_strings.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/funcs/func_strings.c b/funcs/func_strings.c
index 0e315b791..dba306c47 100644
--- a/funcs/func_strings.c
+++ b/funcs/func_strings.c
@@ -296,6 +296,57 @@ struct ast_custom_function strftime_function = {
.read = acf_strftime,
};
+static char *acf_strptime(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
+{
+ AST_DECLARE_APP_ARGS(args,
+ AST_APP_ARG(timestring);
+ AST_APP_ARG(timezone);
+ AST_APP_ARG(format);
+ );
+ 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;
+ }
+
+ AST_STANDARD_APP_ARGS(args, data);
+
+ if (ast_strlen_zero(args.format) ) {
+ ast_log(LOG_ERROR, "No format supplied to STRPTIME(<timestring>|<timezone>|<format>)");
+ return buf;
+ }
+
+ if (!strptime(args.timestring, args.format, &time)) {
+ ast_log(LOG_WARNING, "C function strptime() output nothing?!!\n");
+ } else {
+ snprintf(buf, len, "%d", (int)ast_mktime(&time, args.timezone));
+ }
+
+ 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(<datetime>|<timezone>|<format>)",
+ .desc =
+"This is useful for converting a date into an EPOCH time, possibly to pass to\n"
+"an application like SayUnixTime or to calculate the difference between two\n"
+"date strings.\n"
+"\n"
+"Example:\n"
+" ${STRPTIME(2006-03-01 07:30:35|America/Chicago|%Y-%m-%d %H:%M:%S)} returns 1141219835\n",
+ .read = acf_strptime,
+};
+
static char *function_eval(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
{
memset(buf, 0, len);