aboutsummaryrefslogtreecommitdiffstats
path: root/funcs/func_strings.c
diff options
context:
space:
mode:
authortilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2007-07-18 19:47:20 +0000
committertilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2007-07-18 19:47:20 +0000
commit74c2948c2299773fd3816af43e06e3bdf714ba3a (patch)
tree540f82bac3e6105b6fc34cd4b4613c1756a7512b /funcs/func_strings.c
parentfd471b4a0cbb2abd7b4c8f30fee850cedefedaa1 (diff)
Merge in ast_strftime branch, which changes timestamps to be accurate to the microsecond, instead of only to the second
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@75706 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'funcs/func_strings.c')
-rw-r--r--funcs/func_strings.c29
1 files changed, 19 insertions, 10 deletions
diff --git a/funcs/func_strings.c b/funcs/func_strings.c
index 4619206ee..c44c49921 100644
--- a/funcs/func_strings.c
+++ b/funcs/func_strings.c
@@ -599,20 +599,20 @@ static int acf_strftime(struct ast_channel *chan, const char *cmd, char *parse,
AST_APP_ARG(timezone);
AST_APP_ARG(format);
);
- time_t epochi;
- struct tm tm;
+ struct timeval tv;
+ struct ast_tm tm;
buf[0] = '\0';
AST_STANDARD_APP_ARGS(args, parse);
- ast_get_time_t(args.epoch, &epochi, time(NULL), NULL);
- ast_localtime(&epochi, &tm, args.timezone);
+ ast_get_timeval(args.epoch, &tv, ast_tvnow(), NULL);
+ ast_localtime(&tv, &tm, args.timezone);
if (!args.format)
args.format = "%c";
- if (!strftime(buf, len, args.format, &tm))
+ if (ast_strftime(buf, len, args.format, &tm) <= 0)
ast_log(LOG_WARNING, "C function strftime() output nothing?!!\n");
buf[len - 1] = '\0';
@@ -624,6 +624,14 @@ static struct ast_custom_function strftime_function = {
.name = "STRFTIME",
.synopsis = "Returns the current date/time in a specified format.",
.syntax = "STRFTIME([<epoch>][|[timezone][|format]])",
+ .desc =
+"STRFTIME sports all of the same formats as the underlying C function\n"
+"strftime(3) - see the man page for details. It also supports the\n"
+"following format:\n"
+" %[n]q - fractions of a second, with leading zeroes. For example, %3q will\n"
+" give milliseconds and %1q will give tenths of a second. The default\n"
+" is to output milliseconds (n=3). The common case is to use it in\n"
+" combination with %S, as in \"%S.%3q\".\n",
.read = acf_strftime,
};
@@ -635,9 +643,10 @@ static int acf_strptime(struct ast_channel *chan, const char *cmd, char *data,
AST_APP_ARG(timezone);
AST_APP_ARG(format);
);
- struct tm time;
-
- memset(&time, 0, sizeof(struct tm));
+ union {
+ struct ast_tm atm;
+ struct tm time;
+ } t = { { 0, }, };
buf[0] = '\0';
@@ -655,10 +664,10 @@ static int acf_strptime(struct ast_channel *chan, const char *cmd, char *data,
return -1;
}
- if (!strptime(args.timestring, args.format, &time)) {
+ if (!strptime(args.timestring, args.format, &t.time)) {
ast_log(LOG_WARNING, "C function strptime() output nothing?!!\n");
} else {
- snprintf(buf, len, "%d", (int) ast_mktime(&time, args.timezone));
+ snprintf(buf, len, "%d", (int) ast_mktime(&t.atm, args.timezone));
}
return 0;