From 4662d58b01e5493a39697027285bc22deb2f143c Mon Sep 17 00:00:00 2001 From: "Kevin P. Fleming" Date: Wed, 15 Feb 2006 00:24:24 +0000 Subject: add API function for parsing strings to time_t (issue #6320, with mods) git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@10105 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- apps/app_sayunixtime.c | 47 ++++++++++++++--------------------------------- 1 file changed, 14 insertions(+), 33 deletions(-) (limited to 'apps/app_sayunixtime.c') diff --git a/apps/app_sayunixtime.c b/apps/app_sayunixtime.c index c6db4f140..ad96c6d6f 100644 --- a/apps/app_sayunixtime.c +++ b/apps/app_sayunixtime.c @@ -76,45 +76,26 @@ static int sayunixtime_exec(struct ast_channel *chan, void *data) struct localuser *u; char *s,*zone=NULL,*timec,*format; time_t unixtime; - struct timeval tv; + s = ast_strdupa(data); + if (!s) + return data ? -1 : 0; LOCAL_USER_ADD(u); - tv = ast_tvnow(); - unixtime = (time_t)tv.tv_sec; - - if( !strcasecmp(chan->language, "da" ) ) { - format = "A dBY HMS"; - } else if ( !strcasecmp(chan->language, "de" ) ) { - format = "A dBY HMS"; - } else { - format = "ABdY 'digits/at' IMp"; - } - - if (data) { - s = data; - if ((s = ast_strdupa(s))) { - timec = strsep(&s,"|"); - if ((timec) && (*timec != '\0')) { - long timein; - if (sscanf(timec,"%ld",&timein) == 1) { - unixtime = (time_t)timein; - } - } - if (s) { - zone = strsep(&s,"|"); - if (zone && (*zone == '\0')) - zone = NULL; - if (s) { - format = s; - } - } - } + format = "c"; /* default datetime */ + + timec = strsep(&s,"|"); + ast_get_time_t(timec, &unixtime, time(NULL)); + if (s) { + zone = strsep(&s,"|"); + if (ast_strlen_zero(zone)) + zone = NULL; } + if (s) /* override format */ + format = s; - if (chan->_state != AST_STATE_UP) { + if (chan->_state != AST_STATE_UP) res = ast_answer(chan); - } if (!res) res = ast_say_date_with_format(chan, unixtime, AST_DIGIT_ANY, chan->language, format, zone); -- cgit v1.2.3