diff options
author | tilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b> | 2007-07-18 19:47:20 +0000 |
---|---|---|
committer | tilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b> | 2007-07-18 19:47:20 +0000 |
commit | 74c2948c2299773fd3816af43e06e3bdf714ba3a (patch) | |
tree | 540f82bac3e6105b6fc34cd4b4613c1756a7512b /funcs | |
parent | fd471b4a0cbb2abd7b4c8f30fee850cedefedaa1 (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')
-rw-r--r-- | funcs/func_strings.c | 29 | ||||
-rw-r--r-- | funcs/func_timeout.c | 7 |
2 files changed, 23 insertions, 13 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; diff --git a/funcs/func_timeout.c b/funcs/func_timeout.c index 1da11e54a..ec730c819 100644 --- a/funcs/func_timeout.c +++ b/funcs/func_timeout.c @@ -92,7 +92,7 @@ static int timeout_write(struct ast_channel *chan, const char *cmd, char *data, { int x; char timestr[64]; - struct tm myt; + struct ast_tm myt; if (!chan) return -1; @@ -113,8 +113,9 @@ static int timeout_write(struct ast_channel *chan, const char *cmd, char *data, ast_channel_setwhentohangup(chan, x); if (option_verbose > 2) { if (chan->whentohangup) { - strftime(timestr, sizeof(timestr), "%Y-%m-%d %H:%M:%S UTC", - gmtime_r(&chan->whentohangup, &myt)); + struct timeval tv = { chan->whentohangup, 0 }; + ast_strftime(timestr, sizeof(timestr), "%Y-%m-%d %H:%M:%S.%3q %Z", + ast_localtime(&tv, &myt, NULL)); ast_verbose(VERBOSE_PREFIX_3 "Channel will hangup at %s.\n", timestr); } else { |