From 81bc1d7af5886089bcd065382476f202ad7cc9ea Mon Sep 17 00:00:00 2001 From: Tilghman Lesher Date: Wed, 18 Jul 2007 19:47:20 +0000 Subject: Merge in ast_strftime branch, which changes timestamps to be accurate to the microsecond, instead of only to the second git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@75706 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- main/asterisk.c | 24 +- main/callerid.c | 7 +- main/cdr.c | 9 +- main/cli.c | 69 +++--- main/http.c | 11 +- main/loader.c | 2 +- main/logger.c | 19 +- main/manager.c | 6 +- main/pbx.c | 6 +- main/say.c | 563 +++++++++++++++++++++++------------------------ main/stdtime/localtime.c | 183 +++++++++------ main/utils.c | 27 +++ 12 files changed, 492 insertions(+), 434 deletions(-) (limited to 'main') diff --git a/main/asterisk.c b/main/asterisk.c index eb5654ab4..56c588985 100644 --- a/main/asterisk.c +++ b/main/asterisk.c @@ -193,8 +193,8 @@ struct ast_atexit { static AST_RWLIST_HEAD_STATIC(atexits, ast_atexit); -time_t ast_startuptime; -time_t ast_lastreloadtime; +struct timeval ast_startuptime; +struct timeval ast_lastreloadtime; static History *el_hist; static EditLine *el; @@ -346,7 +346,7 @@ void ast_unregister_thread(void *id) static int handle_show_settings(int fd, int argc, char *argv[]) { char buf[BUFSIZ]; - struct tm tm; + struct ast_tm tm; ast_cli(fd, "\nPBX Core settings\n"); ast_cli(fd, "-----------------\n"); @@ -366,11 +366,11 @@ static int handle_show_settings(int fd, int argc, char *argv[]) ast_cli(fd, " Min Free Memory: %ld MB\n", option_minmemfree); #endif if (ast_localtime(&ast_startuptime, &tm, NULL)) { - strftime(buf, sizeof(buf), "%H:%M:%S", &tm); + ast_strftime(buf, sizeof(buf), "%H:%M:%S", &tm); ast_cli(fd, " Startup time: %s\n", buf); } if (ast_localtime(&ast_lastreloadtime, &tm, NULL)) { - strftime(buf, sizeof(buf), "%H:%M:%S", &tm); + ast_strftime(buf, sizeof(buf), "%H:%M:%S", &tm); ast_cli(fd, " Last reload time: %s\n", buf); } ast_cli(fd, " System: %s/%s built by %s on %s %s\n", ast_build_os, ast_build_kernel, ast_build_user, ast_build_machine, ast_build_date); @@ -1760,8 +1760,8 @@ static char *cli_prompt(EditLine *el) if (*t == '%') { char hostname[MAXHOSTNAMELEN]=""; int i; - time_t ts; - struct tm tm; + struct timeval ts = ast_tvnow(); + struct ast_tm tm = { 0, }; #ifdef linux FILE *LOADAVG; #endif @@ -1783,10 +1783,8 @@ static char *cli_prompt(EditLine *el) color_used = ((fgcolor == COLOR_WHITE) && (bgcolor == COLOR_BLACK)) ? 0 : 1; break; case 'd': /* date */ - memset(&tm, 0, sizeof(tm)); - time(&ts); if (ast_localtime(&ts, &tm, NULL)) - strftime(p, sizeof(prompt) - strlen(prompt), "%Y-%m-%d", &tm); + ast_strftime(p, sizeof(prompt) - strlen(prompt), "%Y-%m-%d", &tm); break; case 'h': /* hostname */ if (!gethostname(hostname, sizeof(hostname) - 1)) @@ -1840,10 +1838,8 @@ static char *cli_prompt(EditLine *el) strncat(p, ast_config_AST_SYSTEM_NAME, sizeof(prompt) - strlen(prompt) - 1); break; case 't': /* time */ - memset(&tm, 0, sizeof(tm)); - time(&ts); if (ast_localtime(&ts, &tm, NULL)) - strftime(p, sizeof(prompt) - strlen(prompt), "%H:%M:%S", &tm); + ast_strftime(p, sizeof(prompt) - strlen(prompt), "%H:%M:%S", &tm); break; case '#': /* process console or remote? */ if (!ast_opt_remote) @@ -2943,7 +2939,7 @@ int main(int argc, char *argv[]) __ast_mm_init(); #endif - time(&ast_startuptime); + ast_startuptime = ast_tvnow(); ast_cli_register_multiple(cli_asterisk, sizeof(cli_asterisk) / sizeof(struct ast_cli_entry)); if (ast_opt_console) { diff --git a/main/callerid.c b/main/callerid.c index 6102d40af..6e3cb9514 100644 --- a/main/callerid.c +++ b/main/callerid.c @@ -684,15 +684,14 @@ void callerid_free(struct callerid_state *cid) static int callerid_genmsg(char *msg, int size, const char *number, const char *name, int flags) { - time_t t; - struct tm tm; + struct timeval tv = ast_tvnow(); + struct ast_tm tm; char *ptr; int res; int i, x; /* Get the time */ - time(&t); - ast_localtime(&t, &tm, NULL); + ast_localtime(&tv, &tm, NULL); ptr = msg; diff --git a/main/cdr.c b/main/cdr.c index e5c96dbec..9a61e0a0d 100644 --- a/main/cdr.c +++ b/main/cdr.c @@ -206,13 +206,10 @@ static void cdr_get_tv(struct timeval tv, const char *fmt, char *buf, int bufsiz if (fmt == NULL) { /* raw mode */ snprintf(buf, bufsize, "%ld.%06ld", (long)tv.tv_sec, (long)tv.tv_usec); } else { - time_t t = tv.tv_sec; - if (t) { - struct tm tm; + struct ast_tm tm; - ast_localtime(&t, &tm, NULL); - strftime(buf, bufsize, fmt, &tm); - } + ast_localtime(&tv, &tm, NULL); + ast_strftime(buf, bufsize, fmt, &tm); } } diff --git a/main/cli.c b/main/cli.c index 7607793ae..235afd2f2 100644 --- a/main/cli.c +++ b/main/cli.c @@ -329,7 +329,7 @@ static int modlist_modentry(const char *module, const char *description, int use return 0; } -static void print_uptimestr(int fd, time_t timeval, const char *prefix, int printsec) +static void print_uptimestr(int fd, struct timeval timeval, const char *prefix, int printsec) { int x; /* the main part - years, weeks, etc. */ struct ast_str *out; @@ -341,40 +341,40 @@ static void print_uptimestr(int fd, time_t timeval, const char *prefix, int prin #define WEEK (DAY*7) #define YEAR (DAY*365) #define NEEDCOMMA(x) ((x)? ",": "") /* define if we need a comma */ - if (timeval < 0) /* invalid, nothing to show */ + if (timeval.tv_sec < 0) /* invalid, nothing to show */ return; if (printsec) { /* plain seconds output */ - ast_cli(fd, "%s: %lu\n", prefix, (u_long)timeval); + ast_cli(fd, "%s: %lu\n", prefix, (u_long)timeval.tv_sec); return; } out = ast_str_alloca(256); - if (timeval > YEAR) { - x = (timeval / YEAR); - timeval -= (x * YEAR); - ast_str_append(&out, 0, "%d year%s%s ", x, ESS(x),NEEDCOMMA(timeval)); - } - if (timeval > WEEK) { - x = (timeval / WEEK); - timeval -= (x * WEEK); - ast_str_append(&out, 0, "%d week%s%s ", x, ESS(x),NEEDCOMMA(timeval)); - } - if (timeval > DAY) { - x = (timeval / DAY); - timeval -= (x * DAY); - ast_str_append(&out, 0, "%d day%s%s ", x, ESS(x),NEEDCOMMA(timeval)); - } - if (timeval > HOUR) { - x = (timeval / HOUR); - timeval -= (x * HOUR); - ast_str_append(&out, 0, "%d hour%s%s ", x, ESS(x),NEEDCOMMA(timeval)); - } - if (timeval > MINUTE) { - x = (timeval / MINUTE); - timeval -= (x * MINUTE); - ast_str_append(&out, 0, "%d minute%s%s ", x, ESS(x),NEEDCOMMA(timeval)); - } - x = timeval; + if (timeval.tv_sec > YEAR) { + x = (timeval.tv_sec / YEAR); + timeval.tv_sec -= (x * YEAR); + ast_str_append(&out, 0, "%d year%s%s ", x, ESS(x),NEEDCOMMA(timeval.tv_sec)); + } + if (timeval.tv_sec > WEEK) { + x = (timeval.tv_sec / WEEK); + timeval.tv_sec -= (x * WEEK); + ast_str_append(&out, 0, "%d week%s%s ", x, ESS(x),NEEDCOMMA(timeval.tv_sec)); + } + if (timeval.tv_sec > DAY) { + x = (timeval.tv_sec / DAY); + timeval.tv_sec -= (x * DAY); + ast_str_append(&out, 0, "%d day%s%s ", x, ESS(x),NEEDCOMMA(timeval.tv_sec)); + } + if (timeval.tv_sec > HOUR) { + x = (timeval.tv_sec / HOUR); + timeval.tv_sec -= (x * HOUR); + ast_str_append(&out, 0, "%d hour%s%s ", x, ESS(x),NEEDCOMMA(timeval.tv_sec)); + } + if (timeval.tv_sec > MINUTE) { + x = (timeval.tv_sec / MINUTE); + timeval.tv_sec -= (x * MINUTE); + ast_str_append(&out, 0, "%d minute%s%s ", x, ESS(x),NEEDCOMMA(timeval.tv_sec)); + } + x = timeval.tv_sec; if (x > 0 || out->used == 0) /* if there is nothing, print 0 seconds */ ast_str_append(&out, 0, "%d second%s ", x, ESS(x)); ast_cli(fd, "%s: %s\n", prefix, out->str); @@ -382,7 +382,7 @@ static void print_uptimestr(int fd, time_t timeval, const char *prefix, int prin static char * handle_showuptime(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { - time_t curtime; + struct timeval curtime = ast_tvnow(); int printsec; switch (cmd) { @@ -404,11 +404,10 @@ static char * handle_showuptime(struct ast_cli_entry *e, int cmd, struct ast_cli printsec = 0; else return CLI_SHOWUSAGE; - curtime = time(NULL); - if (ast_startuptime) - print_uptimestr(a->fd, curtime - ast_startuptime, "System uptime", printsec); - if (ast_lastreloadtime) - print_uptimestr(a->fd, curtime - ast_lastreloadtime, "Last reload", printsec); + if (ast_startuptime.tv_sec) + print_uptimestr(a->fd, ast_tvsub(curtime, ast_startuptime), "System uptime", printsec); + if (ast_lastreloadtime.tv_sec) + print_uptimestr(a->fd, ast_tvsub(curtime, ast_lastreloadtime), "Last reload", printsec); return CLI_SUCCESS; } diff --git a/main/http.c b/main/http.c index d8471740c..b61858cde 100644 --- a/main/http.c +++ b/main/http.c @@ -154,8 +154,9 @@ static struct ast_str *static_callback(struct server_instance *ser, const char * struct stat st; int len; int fd; - time_t t; + struct timeval tv = ast_tvnow(); char buf[256]; + struct ast_tm tm; /* Yuck. I'm not really sold on this, but if you don't deliver static content it makes your configuration substantially more challenging, but this seems like a rather irritating feature creep on Asterisk. */ @@ -186,8 +187,7 @@ static struct ast_str *static_callback(struct server_instance *ser, const char * if (fd < 0) goto out403; - time(&t); - strftime(buf, sizeof(buf), "%a, %d %b %Y %H:%M:%S GMT", gmtime(&t)); + ast_strftime(buf, sizeof(buf), "%a, %d %b %Y %H:%M:%S %Z", ast_localtime(&tv, &tm, "GMT")); fprintf(ser->f, "HTTP/1.1 200 OK\r\n" "Server: Asterisk/%s\r\n" "Date: %s\r\n" @@ -843,10 +843,11 @@ static void *httpd_helper_thread(void *data) ast_variables_destroy(vars); if (out) { - time_t t = time(NULL); + struct timeval tv = ast_tvnow(); char timebuf[256]; + struct ast_tm tm; - strftime(timebuf, sizeof(timebuf), "%a, %d %b %Y %H:%M:%S GMT", gmtime(&t)); + ast_strftime(timebuf, sizeof(timebuf), "%a, %d %b %Y %H:%M:%S %Z", ast_localtime(&tv, &tm, "GMT")); fprintf(ser->f, "HTTP/1.1 %d %s\r\n" "Server: Asterisk/%s\r\n" "Date: %s\r\n" diff --git a/main/loader.c b/main/loader.c index 20227b59e..1100a460f 100644 --- a/main/loader.c +++ b/main/loader.c @@ -551,7 +551,7 @@ int ast_module_reload(const char *name) ast_verbose("The previous reload command didn't finish yet\n"); return -1; /* reload already in progress */ } - ast_lastreloadtime = time(NULL); + ast_lastreloadtime = ast_tvnow(); /* Call "predefined" reload here first */ for (i = 0; reload_classes[i].name; i++) { diff --git a/main/logger.c b/main/logger.c index 1c7ef56a4..6a35ac5fe 100644 --- a/main/logger.c +++ b/main/logger.c @@ -866,8 +866,8 @@ void ast_log(int level, const char *file, int line, const char *function, const { struct logmsg *logmsg = NULL; struct ast_str *buf = NULL; - struct tm tm; - time_t t; + struct ast_tm tm; + struct timeval tv = ast_tvnow(); int res = 0; va_list ap; @@ -929,9 +929,8 @@ void ast_log(int level, const char *file, int line, const char *function, const logmsg->type = LOGMSG_NORMAL; /* Create our date/time */ - time(&t); - ast_localtime(&t, &tm, NULL); - strftime(logmsg->date, sizeof(logmsg->date), dateformat, &tm); + ast_localtime(&tv, &tm, NULL); + ast_strftime(logmsg->date, sizeof(logmsg->date), dateformat, &tm); /* Copy over data */ logmsg->level = level; @@ -993,14 +992,14 @@ void ast_verbose(const char *fmt, ...) return; if (ast_opt_timestamp) { - time_t t; - struct tm tm; + struct timeval tv; + struct ast_tm tm; char date[40]; char *datefmt; - time(&t); - ast_localtime(&t, &tm, NULL); - strftime(date, sizeof(date), dateformat, &tm); + tv = ast_tvnow(); + ast_localtime(&tv, &tm, NULL); + ast_strftime(date, sizeof(date), dateformat, &tm); datefmt = alloca(strlen(date) + 3 + strlen(fmt) + 1); sprintf(datefmt, "[%s] %s", date, fmt); fmt = datefmt; diff --git a/main/manager.c b/main/manager.c index 53059479d..43f825ff4 100644 --- a/main/manager.c +++ b/main/manager.c @@ -2288,15 +2288,15 @@ static int action_corestatus(struct mansession *s, const struct message *m) char idText[150]; char startuptime[150]; char reloadtime[150]; - struct tm tm; + struct ast_tm tm; if (!ast_strlen_zero(actionid)) snprintf(idText, sizeof(idText), "ActionID: %s\r\n", actionid); ast_localtime(&ast_startuptime, &tm, NULL); - strftime(startuptime, sizeof(startuptime), "%H:%M:%S", &tm); + ast_strftime(startuptime, sizeof(startuptime), "%H:%M:%S", &tm); ast_localtime(&ast_lastreloadtime, &tm, NULL); - strftime(reloadtime, sizeof(reloadtime), "%H:%M:%S", &tm); + ast_strftime(reloadtime, sizeof(reloadtime), "%H:%M:%S", &tm); astman_append(s, "Response: Success\r\n" "%s" diff --git a/main/pbx.c b/main/pbx.c index 550add495..918fb5f58 100644 --- a/main/pbx.c +++ b/main/pbx.c @@ -4279,10 +4279,10 @@ int ast_build_timing(struct ast_timing *i, const char *info_in) int ast_check_timing(const struct ast_timing *i) { - struct tm tm; - time_t t = time(NULL); + struct ast_tm tm; + struct timeval tv = ast_tvnow(); - ast_localtime(&t, &tm, NULL); + ast_localtime(&tv, &tm, NULL); /* If it's not the right month, return */ if (!(i->monthmask & (1 << tm.tm_mon))) diff --git a/main/say.c b/main/say.c index e401689f6..85fa93abc 100644 --- a/main/say.c +++ b/main/say.c @@ -2909,10 +2909,11 @@ static int say_date(struct ast_channel *chan, time_t t, const char *ints, const /* English syntax */ int ast_say_date_en(struct ast_channel *chan, time_t t, const char *ints, const char *lang) { - struct tm tm; + struct ast_tm tm; + struct timeval tv = { t, 0 }; char fn[256]; int res = 0; - ast_localtime(&t,&tm,NULL); + ast_localtime(&tv, &tm, NULL); if (!res) { snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday); res = ast_streamfile(chan, fn, lang); @@ -2937,10 +2938,11 @@ int ast_say_date_en(struct ast_channel *chan, time_t t, const char *ints, const /* Danish syntax */ int ast_say_date_da(struct ast_channel *chan, time_t t, const char *ints, const char *lang) { - struct tm tm; + struct timeval tv = { t, 0 }; + struct ast_tm tm; char fn[256]; int res = 0; - ast_localtime(&t,&tm,NULL); + ast_localtime(&tv, &tm, NULL); if (!res) { snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday); res = ast_streamfile(chan, fn, lang); @@ -2985,10 +2987,11 @@ int ast_say_date_da(struct ast_channel *chan, time_t t, const char *ints, const /* German syntax */ int ast_say_date_de(struct ast_channel *chan, time_t t, const char *ints, const char *lang) { - struct tm tm; + struct timeval tv = { t, 0 }; + struct ast_tm tm; char fn[256]; int res = 0; - ast_localtime(&t,&tm,NULL); + ast_localtime(&tv, &tm, NULL); if (!res) { snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday); res = ast_streamfile(chan, fn, lang); @@ -3034,10 +3037,11 @@ int ast_say_date_de(struct ast_channel *chan, time_t t, const char *ints, const /* Hungarian syntax */ int ast_say_date_hu(struct ast_channel *chan, time_t t, const char *ints, const char *lang) { - struct tm tm; + struct timeval tv = { t, 0 }; + struct ast_tm tm; char fn[256]; int res = 0; - ast_localtime(&t,&tm,NULL); + ast_localtime(&tv, &tm, NULL); if (!res) res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL); @@ -3065,10 +3069,11 @@ int ast_say_date_hu(struct ast_channel *chan, time_t t, const char *ints, const /* French syntax */ int ast_say_date_fr(struct ast_channel *chan, time_t t, const char *ints, const char *lang) { - struct tm tm; + struct timeval tv = { t, 0 }; + struct ast_tm tm; char fn[256]; int res = 0; - ast_localtime(&t,&tm,NULL); + ast_localtime(&tv, &tm, NULL); if (!res) { snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday); res = ast_streamfile(chan, fn, lang); @@ -3093,10 +3098,11 @@ int ast_say_date_fr(struct ast_channel *chan, time_t t, const char *ints, const /* Dutch syntax */ int ast_say_date_nl(struct ast_channel *chan, time_t t, const char *ints, const char *lang) { - struct tm tm; + struct timeval tv = { t, 0 }; + struct ast_tm tm; char fn[256]; int res = 0; - ast_localtime(&t,&tm,NULL); + ast_localtime(&tv, &tm, NULL); if (!res) { snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday); res = ast_streamfile(chan, fn, lang); @@ -3121,10 +3127,11 @@ int ast_say_date_nl(struct ast_channel *chan, time_t t, const char *ints, const /* Thai syntax */ int ast_say_date_th(struct ast_channel *chan, time_t t, const char *ints, const char *lang) { - struct tm tm; + struct timeval tv = { t, 0 }; + struct ast_tm tm; char fn[256]; int res = 0; - ast_localtime(&t,&tm,NULL); + ast_localtime(&tv, &tm, NULL); if (!res) { snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday); res = ast_streamfile(chan, fn, lang); @@ -3156,11 +3163,12 @@ int ast_say_date_th(struct ast_channel *chan, time_t t, const char *ints, const /* Portuguese syntax */ int ast_say_date_pt(struct ast_channel *chan, time_t t, const char *ints, const char *lang) { - struct tm tm; + struct timeval tv = { t, 0 }; + struct ast_tm tm; char fn[256]; int res = 0; - ast_localtime(&t, &tm, NULL); + ast_localtime(&tv, &tm, NULL); snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday); if (!res) res = wait_file(chan, ints, fn, lang); @@ -3216,14 +3224,15 @@ static int say_date_with_format(struct ast_channel *chan, time_t time, const cha /* English syntax */ int ast_say_date_with_format_en(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone) { - struct tm tm; + struct timeval tv = { time, 0 }; + struct ast_tm tm; int res=0, offset, sndoffset; char sndfile[256], nextmsg[256]; if (format == NULL) format = "ABdY 'digits/at' IMp"; - ast_localtime(&time,&tm,timezone); + ast_localtime(&tv, &tm, timezone); for (offset=0 ; format[offset] != '\0' ; offset++) { ast_debug(1, "Parsing %c (offset %d) in %s\n", format[offset], offset, format); @@ -3351,16 +3360,15 @@ int ast_say_date_with_format_en(struct ast_channel *chan, time_t time, const cha * language to say the date, with changes in what you say, depending * upon how recent the date is. XXX */ { - struct timeval now; - struct tm tmnow; - time_t beg_today, tt; + struct timeval now = ast_tvnow(); + struct ast_tm tmnow; + time_t beg_today; gettimeofday(&now,NULL); - tt = now.tv_sec; - ast_localtime(&tt,&tmnow,timezone); + ast_localtime(&now, &tmnow, timezone); /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */ /* In any case, it saves not having to do ast_mktime() */ - beg_today = tt - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); + beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); if (beg_today < time) { /* Today */ res = wait_file(chan,ints, "digits/today",lang); @@ -3389,15 +3397,14 @@ int ast_say_date_with_format_en(struct ast_channel *chan, time_t time, const cha * upon how recent the date is. XXX */ { struct timeval now; - struct tm tmnow; - time_t beg_today, tt; + struct ast_tm tmnow; + time_t beg_today; - gettimeofday(&now,NULL); - tt = now.tv_sec; - ast_localtime(&tt,&tmnow,timezone); + now = ast_tvnow(); + ast_localtime(&now, &tmnow, timezone); /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */ /* In any case, it saves not having to do ast_mktime() */ - beg_today = tt - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); + beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); if (beg_today < time) { /* Today */ } else if ((beg_today - 86400) < time) { @@ -3458,14 +3465,15 @@ int ast_say_date_with_format_en(struct ast_channel *chan, time_t time, const cha /* Danish syntax */ int ast_say_date_with_format_da(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone) { - struct tm tm; + struct timeval tv = { time, 0 }; + struct ast_tm tm; int res=0, offset, sndoffset; char sndfile[256], nextmsg[256]; if (!format) format = "A dBY HMS"; - ast_localtime(&time,&tm,timezone); + ast_localtime(&tv, &tm, timezone); for (offset=0 ; format[offset] != '\0' ; offset++) { ast_debug(1, "Parsing %c (offset %d) in %s\n", format[offset], offset, format); @@ -3578,16 +3586,14 @@ int ast_say_date_with_format_da(struct ast_channel *chan, time_t time, const cha * language to say the date, with changes in what you say, depending * upon how recent the date is. XXX */ { - struct timeval now; - struct tm tmnow; - time_t beg_today, tt; + struct timeval now = ast_tvnow(); + struct ast_tm tmnow; + time_t beg_today; - gettimeofday(&now,NULL); - tt = now.tv_sec; - ast_localtime(&tt,&tmnow,timezone); + ast_localtime(&now, &tmnow, timezone); /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */ /* In any case, it saves not having to do ast_mktime() */ - beg_today = tt - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); + beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); if (beg_today < time) { /* Today */ res = wait_file(chan,ints, "digits/today",lang); @@ -3605,16 +3611,14 @@ int ast_say_date_with_format_da(struct ast_channel *chan, time_t time, const cha * language to say the date, with changes in what you say, depending * upon how recent the date is. XXX */ { - struct timeval now; - struct tm tmnow; - time_t beg_today, tt; + struct timeval now = ast_tvnow(); + struct ast_tm tmnow; + time_t beg_today; - gettimeofday(&now,NULL); - tt = now.tv_sec; - ast_localtime(&tt,&tmnow,timezone); + ast_localtime(&now, &tmnow, timezone); /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */ /* In any case, it saves not having to do ast_mktime() */ - beg_today = tt - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); + beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); if (beg_today < time) { /* Today */ } else if ((beg_today - 86400) < time) { @@ -3663,14 +3667,15 @@ int ast_say_date_with_format_da(struct ast_channel *chan, time_t time, const cha /* German syntax */ int ast_say_date_with_format_de(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone) { - struct tm tm; + struct timeval tv = { time, 0 }; + struct ast_tm tm; int res=0, offset, sndoffset; char sndfile[256], nextmsg[256]; if (!format) format = "A dBY HMS"; - ast_localtime(&time,&tm,timezone); + ast_localtime(&tv, &tm, timezone); for (offset=0 ; format[offset] != '\0' ; offset++) { ast_debug(1, "Parsing %c (offset %d) in %s\n", format[offset], offset, format); @@ -3781,16 +3786,14 @@ int ast_say_date_with_format_de(struct ast_channel *chan, time_t time, const cha * language to say the date, with changes in what you say, depending * upon how recent the date is. XXX */ { - struct timeval now; - struct tm tmnow; - time_t beg_today, tt; + struct timeval now = ast_tvnow(); + struct ast_tm tmnow; + time_t beg_today; - gettimeofday(&now,NULL); - tt = now.tv_sec; - ast_localtime(&tt,&tmnow,timezone); + ast_localtime(&now, &tmnow, timezone); /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */ /* In any case, it saves not having to do ast_mktime() */ - beg_today = tt - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); + beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); if (beg_today < time) { /* Today */ res = wait_file(chan,ints, "digits/today",lang); @@ -3808,13 +3811,11 @@ int ast_say_date_with_format_de(struct ast_channel *chan, time_t time, const cha * language to say the date, with changes in what you say, depending * upon how recent the date is. XXX */ { - struct timeval now; - struct tm tmnow; - time_t beg_today, tt; + struct timeval now = ast_tvnow(); + struct ast_tm tmnow; + time_t beg_today; - gettimeofday(&now,NULL); - tt = now.tv_sec; - ast_localtime(&tt,&tmnow,timezone); + ast_localtime(&now, &tmnow, timezone); /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */ /* In any case, it saves not having to do ast_mktime() */ beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); @@ -3866,14 +3867,15 @@ int ast_say_date_with_format_de(struct ast_channel *chan, time_t time, const cha /* Thai syntax */ int ast_say_date_with_format_th(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone) { - struct tm tm; + struct timeval tv = { time, 0 }; + struct ast_tm tm; int res=0, offset, sndoffset; char sndfile[256], nextmsg[256]; if (format == NULL) format = "a 'digits/tee' e 'digits/duan' hY I 'digits/naliga' M 'digits/natee'"; - ast_localtime(&time,&tm,timezone); + ast_localtime(&tv, &tm, timezone); for (offset=0 ; format[offset] != '\0' ; offset++) { ast_log(LOG_DEBUG, "Parsing %c (offset %d) in %s\n", format[offset], offset, format); @@ -3942,16 +3944,14 @@ int ast_say_date_with_format_th(struct ast_channel *chan, time_t time, const cha * language to say the date, with changes in what you say, depending * upon how recent the date is. XXX */ { - struct timeval now; - struct tm tmnow; - time_t beg_today, tt; + struct timeval now = ast_tvnow(); + struct ast_tm tmnow; + time_t beg_today; - gettimeofday(&now,NULL); - tt = now.tv_sec; - ast_localtime(&tt,&tmnow,timezone); + ast_localtime(&now, &tmnow, timezone); /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */ /* In any case, it saves not having to do ast_mktime() */ - beg_today = tt - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); + beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); if (beg_today < time) { /* Today */ res = wait_file(chan,ints, "digits/today",lang); @@ -3979,16 +3979,14 @@ int ast_say_date_with_format_th(struct ast_channel *chan, time_t time, const cha * language to say the date, with changes in what you say, depending * upon how recent the date is. XXX */ { - struct timeval now; - struct tm tmnow; - time_t beg_today, tt; + struct timeval now = ast_tvnow(); + struct ast_tm tmnow; + time_t beg_today; - gettimeofday(&now,NULL); - tt = now.tv_sec; - ast_localtime(&tt,&tmnow,timezone); + ast_localtime(&now, &tmnow, timezone); /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */ /* In any case, it saves not having to do ast_mktime() */ - beg_today = tt - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); + beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); if (beg_today < time) { /* Today */ } else if ((beg_today - 86400) < time) { @@ -4064,14 +4062,15 @@ int ast_say_date_with_format_he(struct ast_channel *chan, time_t time, /* TODO: This whole function is cut&paste from * ast_say_date_with_format_en . Is that considered acceptable? **/ - struct tm tm; + struct timeval tv = { time, 0 }; + struct ast_tm tm; int res=0, offset, sndoffset; char sndfile[256], nextmsg[256]; if (!format) format = IL_DATE_STR_FULL; - ast_localtime(&time,&tm,timezone); + ast_localtime(&tv, &tm, timezone); for (offset=0 ; format[offset] != '\0' ; offset++) { ast_debug(1, "Parsing %c (offset %d) in %s\n", format[offset], offset, format); @@ -4165,17 +4164,15 @@ int ast_say_date_with_format_he(struct ast_channel *chan, time_t time, * language to say the date, with changes in what you say, depending * upon how recent the date is. XXX */ { - struct timeval now; - struct tm tmnow; - time_t beg_today, tt; + struct timeval now = ast_tvnow(); + struct ast_tm tmnow; + time_t beg_today; char todo = format[offset]; /* The letter to format*/ - gettimeofday(&now,NULL); - tt = now.tv_sec; - ast_localtime(&tt,&tmnow,timezone); + ast_localtime(&now, &tmnow, timezone); /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */ /* In any case, it saves not having to do ast_mktime() */ - beg_today = tt - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); + beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); if (beg_today < time) { /* Today */ if (todo == 'Q') { @@ -4246,14 +4243,15 @@ int ast_say_date_with_format_he(struct ast_channel *chan, time_t time, /* Spanish syntax */ int ast_say_date_with_format_es(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone) { - struct tm tm; + struct timeval tv = { time, 0 }; + struct ast_tm tm; int res=0, offset, sndoffset; char sndfile[256], nextmsg[256]; if (format == NULL) format = "'digits/es-el' Ad 'digits/es-de' B 'digits/es-de' Y 'digits/at' IMp"; - ast_localtime(&time,&tm,timezone); + ast_localtime(&tv, &tm, timezone); for (offset=0 ; format[offset] != '\0' ; offset++) { ast_debug(1, "Parsing %c (offset %d) in %s\n", format[offset], offset, format); @@ -4331,16 +4329,14 @@ int ast_say_date_with_format_es(struct ast_channel *chan, time_t time, const cha * language to say the date, with changes in what you say, depending * upon how recent the date is. XXX */ { - struct timeval now; - struct tm tmnow; - time_t beg_today, tt; + struct timeval now = ast_tvnow(); + struct ast_tm tmnow; + time_t beg_today; - gettimeofday(&now,NULL); - tt = now.tv_sec; - ast_localtime(&tt,&tmnow,timezone); + ast_localtime(&now, &tmnow, timezone); /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */ /* In any case, it saves not having to do ast_mktime() */ - beg_today = tt - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); + beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); if (beg_today < time) { /* Today */ res = wait_file(chan,ints, "digits/today",lang); @@ -4358,16 +4354,14 @@ int ast_say_date_with_format_es(struct ast_channel *chan, time_t time, const cha * language to say the date, with changes in what you say, depending * upon how recent the date is. XXX */ { - struct timeval now; - struct tm tmnow; - time_t beg_today, tt; + struct timeval now = ast_tvnow(); + struct ast_tm tmnow; + time_t beg_today; - gettimeofday(&now,NULL); - tt = now.tv_sec; - ast_localtime(&tt,&tmnow,timezone); + ast_localtime(&now, &tmnow, timezone); /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */ /* In any case, it saves not having to do ast_mktime() */ - beg_today = tt - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); + beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); if (beg_today < time) { /* Today */ res = wait_file(chan,ints, "digits/today",lang); @@ -4438,14 +4432,15 @@ oclock = heure */ int ast_say_date_with_format_fr(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone) { - struct tm tm; + struct timeval tv = { time, 0 }; + struct ast_tm tm; int res=0, offset, sndoffset; char sndfile[256], nextmsg[256]; if (format == NULL) format = "AdBY 'digits/at' IMp"; - ast_localtime(&time,&tm,timezone); + ast_localtime(&tv, &tm, timezone); for (offset=0 ; format[offset] != '\0' ; offset++) { ast_debug(1, "Parsing %c (offset %d) in %s\n", format[offset], offset, format); @@ -4555,16 +4550,14 @@ int ast_say_date_with_format_fr(struct ast_channel *chan, time_t time, const cha * language to say the date, with changes in what you say, depending * upon how recent the date is. XXX */ { - struct timeval now; - struct tm tmnow; - time_t beg_today, tt; + struct timeval now = ast_tvnow(); + struct ast_tm tmnow; + time_t beg_today; - gettimeofday(&now,NULL); - tt = now.tv_sec; - ast_localtime(&tt,&tmnow,timezone); + ast_localtime(&now, &tmnow, timezone); /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */ /* In any case, it saves not having to do ast_mktime() */ - beg_today = tt - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); + beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); if (beg_today < time) { /* Today */ res = wait_file(chan,ints, "digits/today",lang); @@ -4582,16 +4575,14 @@ int ast_say_date_with_format_fr(struct ast_channel *chan, time_t time, const cha * language to say the date, with changes in what you say, depending * upon how recent the date is. XXX */ { - struct timeval now; - struct tm tmnow; - time_t beg_today, tt; + struct timeval now = ast_tvnow(); + struct ast_tm tmnow; + time_t beg_today; - gettimeofday(&now,NULL); - tt = now.tv_sec; - ast_localtime(&tt,&tmnow,timezone); + ast_localtime(&now, &tmnow, timezone); /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */ /* In any case, it saves not having to do ast_mktime() */ - beg_today = tt - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); + beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); if (beg_today < time) { /* Today */ } else if ((beg_today - 86400) < time) { @@ -4636,14 +4627,15 @@ int ast_say_date_with_format_fr(struct ast_channel *chan, time_t time, const cha int ast_say_date_with_format_it(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone) { - struct tm tm; + struct timeval tv = { time, 0 }; + struct ast_tm tm; int res=0, offset, sndoffset; char sndfile[256], nextmsg[256]; if (format == NULL) format = "AdB 'digits/at' IMp"; - ast_localtime(&time,&tm,timezone); + ast_localtime(&tv, &tm, timezone); for (offset=0 ; format[offset] != '\0' ; offset++) { ast_debug(1, "Parsing %c (offset %d) in %s\n", format[offset], offset, format); @@ -4653,7 +4645,7 @@ int ast_say_date_with_format_it(struct ast_channel *chan, time_t time, const cha /* Literal name of a sound file */ sndoffset=0; for (sndoffset=0 ; (format[++offset] != '\'') && (sndoffset < 256) ; sndoffset++) - sndfile[sndoffset] = format[offset]; + sndfile[sndoffset] = format[offset]; sndfile[sndoffset] = '\0'; res = wait_file(chan,ints,sndfile,lang); break; @@ -4768,16 +4760,14 @@ int ast_say_date_with_format_it(struct ast_channel *chan, time_t time, const cha * language to say the date, with changes in what you say, depending * upon how recent the date is. XXX */ { - struct timeval now; - struct tm tmnow; - time_t beg_today, tt; + struct timeval now = ast_tvnow(); + struct ast_tm tmnow; + time_t beg_today; - gettimeofday(&now,NULL); - tt = now.tv_sec; - ast_localtime(&tt,&tmnow,timezone); + ast_localtime(&now, &tmnow, timezone); /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */ /* In any case, it saves not having to do ast_mktime() */ - beg_today = tt - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); + beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); if (beg_today < time) { /* Today */ res = wait_file(chan,ints, "digits/today",lang); @@ -4792,16 +4782,14 @@ int ast_say_date_with_format_it(struct ast_channel *chan, time_t time, const cha case 'q': /* Shorthand for "" (today), "Yesterday", A (weekday), or ABdY */ { - struct timeval now; - struct tm tmnow; - time_t beg_today, tt; + struct timeval now = ast_tvnow(); + struct ast_tm tmnow; + time_t beg_today; - gettimeofday(&now,NULL); - tt = now.tv_sec; - ast_localtime(&tt,&tmnow,timezone); + ast_localtime(&now, &tmnow, timezone); /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */ /* In any case, it saves not having to do ast_mktime() */ - beg_today = tt - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); + beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); if (beg_today < time) { /* Today */ } else if ((beg_today - 86400) < time) { @@ -4869,14 +4857,15 @@ int ast_say_date_with_format_it(struct ast_channel *chan, time_t time, const cha /* Dutch syntax */ int ast_say_date_with_format_nl(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone) { - struct tm tm; + struct timeval tv = { time, 0 }; + struct ast_tm tm; int res=0, offset, sndoffset; char sndfile[256], nextmsg[256]; if (format == NULL) format = "ABdY 'digits/at' IMp"; - ast_localtime(&time,&tm,timezone); + ast_localtime(&tv, &tm, timezone); for (offset=0 ; format[offset] != '\0' ; offset++) { ast_debug(1, "Parsing %c (offset %d) in %s\n", format[offset], offset, format); @@ -5001,16 +4990,14 @@ int ast_say_date_with_format_nl(struct ast_channel *chan, time_t time, const cha * language to say the date, with changes in what you say, depending * upon how recent the date is. XXX */ { - struct timeval now; - struct tm tmnow; - time_t beg_today, tt; + struct timeval now = ast_tvnow(); + struct ast_tm tmnow; + time_t beg_today; - gettimeofday(&now,NULL); - tt = now.tv_sec; - ast_localtime(&tt,&tmnow,timezone); + ast_localtime(&now, &tmnow, timezone); /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */ /* In any case, it saves not having to do ast_mktime() */ - beg_today = tt - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); + beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); if (beg_today < time) { /* Today */ res = wait_file(chan,ints, "digits/today",lang); @@ -5025,16 +5012,14 @@ int ast_say_date_with_format_nl(struct ast_channel *chan, time_t time, const cha case 'q': /* Shorthand for "" (today), "Yesterday", A (weekday), or ABdY */ { - struct timeval now; - struct tm tmnow; - time_t beg_today, tt; + struct timeval now = ast_tvnow(); + struct ast_tm tmnow; + time_t beg_today; - gettimeofday(&now,NULL); - tt = now.tv_sec; - ast_localtime(&tt,&tmnow,timezone); + ast_localtime(&now, &tmnow, timezone); /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */ /* In any case, it saves not having to do ast_mktime() */ - beg_today = tt - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); + beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); if (beg_today < time) { /* Today */ } else if ((beg_today - 86400) < time) { @@ -5077,11 +5062,12 @@ int ast_say_date_with_format_nl(struct ast_channel *chan, time_t time, const cha /* Polish syntax */ int ast_say_date_with_format_pl(struct ast_channel *chan, time_t thetime, const char *ints, const char *lang, const char *format, const char *timezone) { - struct tm tm; + struct timeval tv = { thetime, 0 }; + struct ast_tm tm; int res=0, offset, sndoffset; char sndfile[256], nextmsg[256]; - ast_localtime(&thetime, &tm, timezone); + ast_localtime(&tv, &tm, timezone); for (offset = 0 ; format[offset] != '\0' ; offset++) { int remainder; @@ -5203,14 +5189,14 @@ int ast_say_date_with_format_pl(struct ast_channel *chan, time_t thetime, const case 'Q': /* Shorthand for "Today", "Yesterday", or AdBY */ { - time_t tv_sec = time(NULL); - struct tm tmnow; + struct timeval now = ast_tvnow(); + struct ast_tm tmnow; time_t beg_today; - ast_localtime(&tv_sec,&tmnow, timezone); + ast_localtime(&now, &tmnow, timezone); /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */ /* In any case, it saves not having to do ast_mktime() */ - beg_today = tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); + beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); if (beg_today < thetime) { /* Today */ res = wait_file(chan, ints, "digits/today", lang); @@ -5225,14 +5211,14 @@ int ast_say_date_with_format_pl(struct ast_channel *chan, time_t thetime, const case 'q': /* Shorthand for "" (today), "Yesterday", A (weekday), or AdBY */ { - time_t tv_sec = time(NULL); - struct tm tmnow; + struct timeval now = ast_tvnow(); + struct ast_tm tmnow; time_t beg_today; - ast_localtime(&tv_sec, &tmnow, timezone); + ast_localtime(&now, &tmnow, timezone); /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */ /* In any case, it saves not having to do ast_mktime() */ - beg_today = tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); + beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); if (beg_today < thetime) { /* Today */ } else if ((beg_today - 86400) < thetime) { @@ -5293,14 +5279,15 @@ int ast_say_date_with_format_pl(struct ast_channel *chan, time_t thetime, const /* Portuguese syntax */ int ast_say_date_with_format_pt(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone) { - struct tm tm; + struct timeval tv = { time, 0 }; + struct ast_tm tm; int res=0, offset, sndoffset; char sndfile[256], nextmsg[256]; if (format == NULL) format = "Ad 'digits/pt-de' B 'digits/pt-de' Y 'digits/at' IMp"; - ast_localtime(&time,&tm,timezone); + ast_localtime(&tv, &tm, timezone); for (offset=0 ; format[offset] != '\0' ; offset++) { ast_debug(1, "Parsing %c (offset %d) in %s\n", format[offset], offset, format); @@ -5476,16 +5463,14 @@ int ast_say_date_with_format_pt(struct ast_channel *chan, time_t time, const cha * language to say the date, with changes in what you say, depending * upon how recent the date is. XXX */ { - struct timeval now; - struct tm tmnow; - time_t beg_today, tt; + struct timeval now = ast_tvnow(); + struct ast_tm tmnow; + time_t beg_today; - gettimeofday(&now,NULL); - tt = now.tv_sec; - ast_localtime(&tt,&tmnow,timezone); + ast_localtime(&now, &tmnow, timezone); /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */ /* In any case, it saves not having to do ast_mktime() */ - beg_today = tt - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); + beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); if (beg_today < time) { /* Today */ res = wait_file(chan,ints, "digits/today",lang); @@ -5503,16 +5488,14 @@ int ast_say_date_with_format_pt(struct ast_channel *chan, time_t time, const cha * language to say the date, with changes in what you say, depending * upon how recent the date is. XXX */ { - struct timeval now; - struct tm tmnow; - time_t beg_today, tt; + struct timeval now = ast_tvnow(); + struct ast_tm tmnow; + time_t beg_today; - gettimeofday(&now,NULL); - tt = now.tv_sec; - ast_localtime(&tt,&tmnow,timezone); + ast_localtime(&now, &tmnow, timezone); /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */ /* In any case, it saves not having to do ast_mktime() */ - beg_today = tt - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); + beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); if (beg_today < time) { /* Today */ } else if ((beg_today - 86400) < time) { @@ -5591,14 +5574,15 @@ int ast_say_date_with_format_pt(struct ast_channel *chan, time_t time, const cha /* Taiwanese / Chinese syntax */ int ast_say_date_with_format_tw(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone) { - struct tm tm; + struct timeval tv = { time, 0 }; + struct ast_tm tm; int res=0, offset, sndoffset; char sndfile[256], nextmsg[256]; if (format == NULL) format = "YBdAkM"; - ast_localtime(&time,&tm,timezone); + ast_localtime(&tv, &tm, timezone); for (offset=0 ; format[offset] != '\0' ; offset++) { ast_debug(1, "Parsing %c (offset %d) in %s\n", format[offset], offset, format); @@ -5769,16 +5753,14 @@ int ast_say_date_with_format_tw(struct ast_channel *chan, time_t time, const cha * language to say the date, with changes in what you say, depending * upon how recent the date is. XXX */ { - struct timeval now; - struct tm tmnow; - time_t beg_today, tt; + struct timeval now = ast_tvnow(); + struct ast_tm tmnow; + time_t beg_today; - gettimeofday(&now,NULL); - tt = now.tv_sec; - ast_localtime(&tt,&tmnow,timezone); + ast_localtime(&now, &tmnow, timezone); /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */ /* In any case, it saves not having to do ast_mktime() */ - beg_today = tt - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); + beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); if (beg_today < time) { /* Today */ res = wait_file(chan,ints, "digits/today",lang); @@ -5796,16 +5778,14 @@ int ast_say_date_with_format_tw(struct ast_channel *chan, time_t time, const cha * language to say the date, with changes in what you say, depending * upon how recent the date is. XXX */ { - struct timeval now; - struct tm tmnow; - time_t beg_today, tt; + struct timeval now = ast_tvnow(); + struct ast_tm tmnow; + time_t beg_today; - gettimeofday(&now,NULL); - tt = now.tv_sec; - ast_localtime(&tt,&tmnow,timezone); + ast_localtime(&now, &tmnow, timezone); /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */ /* In any case, it saves not having to do ast_mktime() */ - beg_today = tt - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); + beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); if (beg_today < time) { /* Today */ } else if ((beg_today - 86400) < time) { @@ -5895,11 +5875,12 @@ static int say_time(struct ast_channel *chan, time_t t, const char *ints, const /* English syntax */ int ast_say_time_en(struct ast_channel *chan, time_t t, const char *ints, const char *lang) { - struct tm tm; + struct timeval tv = { t, 0 }; + struct ast_tm tm; int res = 0; int hour, pm=0; - ast_localtime(&t, &tm, NULL); + ast_localtime(&tv, &tm, NULL); hour = tm.tm_hour; if (!hour) hour = 12; @@ -5943,10 +5924,11 @@ int ast_say_time_en(struct ast_channel *chan, time_t t, const char *ints, const /* German syntax */ int ast_say_time_de(struct ast_channel *chan, time_t t, const char *ints, const char *lang) { - struct tm tm; + struct timeval tv = { t, 0 }; + struct ast_tm tm; int res = 0; - ast_localtime(&t, &tm, NULL); + ast_localtime(&tv, &tm, NULL); if (!res) res = ast_say_number(chan, tm.tm_hour, ints, lang, "n"); if (!res) @@ -5962,10 +5944,11 @@ int ast_say_time_de(struct ast_channel *chan, time_t t, const char *ints, const /* Hungarian syntax */ int ast_say_time_hu(struct ast_channel *chan, time_t t, const char *ints, const char *lang) { - struct tm tm; + struct timeval tv = { t, 0 }; + struct ast_tm tm; int res = 0; - ast_localtime(&t, &tm, NULL); + ast_localtime(&tv, &tm, NULL); if (!res) res = ast_say_number(chan, tm.tm_hour, ints, lang, "n"); if (!res) @@ -5984,10 +5967,11 @@ int ast_say_time_hu(struct ast_channel *chan, time_t t, const char *ints, const /* French syntax */ int ast_say_time_fr(struct ast_channel *chan, time_t t, const char *ints, const char *lang) { - struct tm tm; + struct timeval tv = { t, 0 }; + struct ast_tm tm; int res = 0; - ast_localtime(&t, &tm, NULL); + ast_localtime(&tv, &tm, NULL); res = ast_say_number(chan, tm.tm_hour, ints, lang, "f"); if (!res) @@ -6002,10 +5986,11 @@ int ast_say_time_fr(struct ast_channel *chan, time_t t, const char *ints, const /* Dutch syntax */ int ast_say_time_nl(struct ast_channel *chan, time_t t, const char *ints, const char *lang) { - struct tm tm; + struct timeval tv = { t, 0 }; + struct ast_tm tm; int res = 0; - ast_localtime(&t, &tm, NULL); + ast_localtime(&tv, &tm, NULL); if (!res) res = ast_say_number(chan, tm.tm_hour, ints, lang, (char *) NULL); if (!res) @@ -6021,11 +6006,12 @@ int ast_say_time_nl(struct ast_channel *chan, time_t t, const char *ints, const /* Portuguese syntax */ int ast_say_time_pt(struct ast_channel *chan, time_t t, const char *ints, const char *lang) { - struct tm tm; + struct timeval tv = { t, 0 }; + struct ast_tm tm; int res = 0; int hour; - ast_localtime(&t, &tm, NULL); + ast_localtime(&tv, &tm, NULL); hour = tm.tm_hour; if (!res) res = ast_say_number(chan, hour, ints, lang, "f"); @@ -6049,10 +6035,11 @@ int ast_say_time_pt(struct ast_channel *chan, time_t t, const char *ints, const /* Brazilian Portuguese syntax */ int ast_say_time_pt_BR(struct ast_channel *chan, time_t t, const char *ints, const char *lang) { - struct tm tm; + struct timeval tv = { t, 0 }; + struct ast_tm tm; int res = 0; - ast_localtime(&t, &tm, NULL); + ast_localtime(&tv, &tm, NULL); res = ast_say_number(chan, tm.tm_hour, ints, lang, "f"); if (!res) { @@ -6078,10 +6065,11 @@ int ast_say_time_pt_BR(struct ast_channel *chan, time_t t, const char *ints, con /* Thai syntax */ int ast_say_time_th(struct ast_channel *chan, time_t t, const char *ints, const char *lang) { - struct tm tm; + struct timeval tv = { t, 0 }; + struct ast_tm tm; int res = 0; int hour; - ast_localtime(&t, &tm, NULL); + ast_localtime(&tv, &tm, NULL); hour = tm.tm_hour; if (!hour) hour = 24; @@ -6095,11 +6083,12 @@ int ast_say_time_th(struct ast_channel *chan, time_t t, const char *ints, const /* Taiwanese / Chinese syntax */ int ast_say_time_tw(struct ast_channel *chan, time_t t, const char *ints, const char *lang) { - struct tm tm; + struct timeval tv = { t, 0 }; + struct ast_tm tm; int res = 0; int hour, pm=0; - ast_localtime(&t, &tm, NULL); + ast_localtime(&tv, &tm, NULL); hour = tm.tm_hour; if (!hour) hour = 12; @@ -6166,12 +6155,13 @@ static int say_datetime(struct ast_channel *chan, time_t t, const char *ints, co /* English syntax */ int ast_say_datetime_en(struct ast_channel *chan, time_t t, const char *ints, const char *lang) { - struct tm tm; + struct timeval tv = { t, 0 }; + struct ast_tm tm; char fn[256]; int res = 0; int hour, pm=0; - ast_localtime(&t, &tm, NULL); + ast_localtime(&tv, &tm, NULL); if (!res) { snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday); res = ast_streamfile(chan, fn, lang); @@ -6232,10 +6222,11 @@ int ast_say_datetime_en(struct ast_channel *chan, time_t t, const char *ints, co /* German syntax */ int ast_say_datetime_de(struct ast_channel *chan, time_t t, const char *ints, const char *lang) { - struct tm tm; + struct timeval tv = { t, 0 }; + struct ast_tm tm; int res = 0; - ast_localtime(&t, &tm, NULL); + ast_localtime(&tv, &tm, NULL); res = ast_say_date(chan, t, ints, lang); if (!res) ast_say_time(chan, t, ints, lang); @@ -6246,10 +6237,11 @@ int ast_say_datetime_de(struct ast_channel *chan, time_t t, const char *ints, co /* Hungarian syntax */ int ast_say_datetime_hu(struct ast_channel *chan, time_t t, const char *ints, const char *lang) { - struct tm tm; + struct timeval tv = { t, 0 }; + struct ast_tm tm; int res = 0; - ast_localtime(&t, &tm, NULL); + ast_localtime(&tv, &tm, NULL); res = ast_say_date(chan, t, ints, lang); if (!res) ast_say_time(chan, t, ints, lang); @@ -6259,11 +6251,12 @@ int ast_say_datetime_hu(struct ast_channel *chan, time_t t, const char *ints, co /* French syntax */ int ast_say_datetime_fr(struct ast_channel *chan, time_t t, const char *ints, const char *lang) { - struct tm tm; + struct timeval tv = { t, 0 }; + struct ast_tm tm; char fn[256]; int res = 0; - ast_localtime(&t, &tm, NULL); + ast_localtime(&tv, &tm, NULL); if (!res) res = ast_say_number(chan, tm.tm_mday, ints, lang, (char *) NULL); @@ -6299,10 +6292,11 @@ int ast_say_datetime_fr(struct ast_channel *chan, time_t t, const char *ints, co /* Dutch syntax */ int ast_say_datetime_nl(struct ast_channel *chan, time_t t, const char *ints, const char *lang) { - struct tm tm; + struct timeval tv = { t, 0 }; + struct ast_tm tm; int res = 0; - ast_localtime(&t, &tm, NULL); + ast_localtime(&tv, &tm, NULL); res = ast_say_date(chan, t, ints, lang); if (!res) { res = ast_streamfile(chan, "digits/nl-om", lang); @@ -6317,12 +6311,13 @@ int ast_say_datetime_nl(struct ast_channel *chan, time_t t, const char *ints, co /* Portuguese syntax */ int ast_say_datetime_pt(struct ast_channel *chan, time_t t, const char *ints, const char *lang) { - struct tm tm; + struct timeval tv = { t, 0 }; + struct ast_tm tm; char fn[256]; int res = 0; int hour, pm=0; - ast_localtime(&t, &tm, NULL); + ast_localtime(&tv, &tm, NULL); if (!res) { snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday); res = ast_streamfile(chan, fn, lang); @@ -6383,10 +6378,11 @@ int ast_say_datetime_pt(struct ast_channel *chan, time_t t, const char *ints, co /* Brazilian Portuguese syntax */ int ast_say_datetime_pt_BR(struct ast_channel *chan, time_t t, const char *ints, const char *lang) { - struct tm tm; + struct timeval tv = { t, 0 }; + struct ast_tm tm; int res = 0; - ast_localtime(&t, &tm, NULL); + ast_localtime(&tv, &tm, NULL); res = ast_say_date(chan, t, ints, lang); if (!res) res = ast_say_time(chan, t, ints, lang); @@ -6396,11 +6392,12 @@ int ast_say_datetime_pt_BR(struct ast_channel *chan, time_t t, const char *ints, /* Thai syntax */ int ast_say_datetime_th(struct ast_channel *chan, time_t t, const char *ints, const char *lang) { - struct tm tm; + struct timeval tv = { t, 0 }; + struct ast_tm tm; char fn[256]; int res = 0; int hour; - ast_localtime(&t, &tm, NULL); + ast_localtime(&tv, &tm, NULL); if (!res) { snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday); res = ast_streamfile(chan, fn, lang); @@ -6438,12 +6435,13 @@ int ast_say_datetime_th(struct ast_channel *chan, time_t t, const char *ints, co /* Taiwanese / Chinese syntax */ int ast_say_datetime_tw(struct ast_channel *chan, time_t t, const char *ints, const char *lang) { - struct tm tm; + struct timeval tv = { t, 0 }; + struct ast_tm tm; char fn[256]; int res = 0; int hour, pm=0; - ast_localtime(&t, &tm, NULL); + ast_localtime(&tv, &tm, NULL); if (!res) res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL); if (!res) { @@ -6514,16 +6512,14 @@ static int say_datetime_from_now(struct ast_channel *chan, time_t t, const char int ast_say_datetime_from_now_en(struct ast_channel *chan, time_t t, const char *ints, const char *lang) { int res=0; - time_t nowt; + struct timeval nowtv = ast_tvnow(), tv = { t, 0 }; int daydiff; - struct tm tm; - struct tm now; + struct ast_tm tm; + struct ast_tm now; char fn[256]; - time(&nowt); - - ast_localtime(&t, &tm, NULL); - ast_localtime(&nowt,&now, NULL); + ast_localtime(&tv, &tm, NULL); + ast_localtime(&nowtv, &now, NULL); daydiff = now.tm_yday - tm.tm_yday; if ((daydiff < 0) || (daydiff > 6)) { /* Day of month and month */ @@ -6554,16 +6550,14 @@ int ast_say_datetime_from_now_en(struct ast_channel *chan, time_t t, const char int ast_say_datetime_from_now_fr(struct ast_channel *chan, time_t t, const char *ints, const char *lang) { int res=0; - time_t nowt; + struct timeval nowtv = ast_tvnow(), tv = { t, 0 }; int daydiff; - struct tm tm; - struct tm now; + struct ast_tm tm; + struct ast_tm now; char fn[256]; - time(&nowt); - - ast_localtime(&t, &tm, NULL); - ast_localtime(&nowt, &now, NULL); + ast_localtime(&tv, &tm, NULL); + ast_localtime(&nowtv, &now, NULL); daydiff = now.tm_yday - tm.tm_yday; if ((daydiff < 0) || (daydiff > 6)) { /* Day of month and month */ @@ -6594,16 +6588,14 @@ int ast_say_datetime_from_now_fr(struct ast_channel *chan, time_t t, const char int ast_say_datetime_from_now_pt(struct ast_channel *chan, time_t t, const char *ints, const char *lang) { int res=0; - time_t nowt; int daydiff; - struct tm tm; - struct tm now; + struct ast_tm tm; + struct ast_tm now; + struct timeval nowtv = ast_tvnow(), tv = { t, 0 }; char fn[256]; - time(&nowt); - - ast_localtime(&t, &tm, NULL); - ast_localtime(&nowt, &now, NULL); + ast_localtime(&tv, &tm, NULL); + ast_localtime(&nowtv, &now, NULL); daydiff = now.tm_yday - tm.tm_yday; if ((daydiff < 0) || (daydiff > 6)) { /* Day of month and month */ @@ -6778,13 +6770,14 @@ static int ast_say_number_full_gr(struct ast_channel *chan, int num, const char static int ast_say_date_gr(struct ast_channel *chan, time_t t, const char *ints, const char *lang) { - struct tm tm; + struct ast_tm tm; + struct timeval tv = { t, 0 }; char fn[256]; int res = 0; - ast_localtime(&t,&tm,NULL); + ast_localtime(&tv, &tm, NULL); /* W E E K - D A Y */ if (!res) { snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday); @@ -6822,11 +6815,12 @@ static int ast_say_date_gr(struct ast_channel *chan, time_t t, const char *ints, static int ast_say_time_gr(struct ast_channel *chan, time_t t, const char *ints, const char *lang) { - struct tm tm; + struct timeval tv = { t, 0 }; + struct ast_tm tm; int res = 0; int hour, pm=0; - ast_localtime(&t, &tm, NULL); + ast_localtime(&tv, &tm, NULL); hour = tm.tm_hour; if (!hour) @@ -6868,13 +6862,13 @@ static int ast_say_time_gr(struct ast_channel *chan, time_t t, const char *ints, static int ast_say_datetime_gr(struct ast_channel *chan, time_t t, const char *ints, const char *lang) { - struct tm tm; + struct timeval tv = { t, 0 }; + struct ast_tm tm; char fn[256]; int res = 0; - ast_localtime(&t, &tm, NULL); + ast_localtime(&tv, &tm, NULL); - /* W E E K - D A Y */ if (!res) { snprintf(fn, sizeof(fn), "digits/day-%d", tm.tm_wday); @@ -6900,15 +6894,15 @@ static int ast_say_datetime_gr(struct ast_channel *chan, time_t t, const char *i static int ast_say_date_with_format_gr(struct ast_channel *chan, time_t time, const char *ints, const char *lang, const char *format, const char *timezone) { - - struct tm tm; + struct timeval tv = { time, 0 }; + struct ast_tm tm; int res=0, offset, sndoffset; char sndfile[256], nextmsg[256]; if (!format) format = "AdBY 'digits/at' IMp"; - ast_localtime(&time,&tm,timezone); + ast_localtime(&tv, &tm, timezone); for (offset=0 ; format[offset] != '\0' ; offset++) { ast_debug(1, "Parsing %c (offset %d) in %s\n", format[offset], offset, format); @@ -6991,16 +6985,14 @@ static int ast_say_date_with_format_gr(struct ast_channel *chan, time_t time, co * language to say the date, with changes in what you say, depending * upon how recent the date is. XXX */ { - struct timeval now; - struct tm tmnow; - time_t beg_today, tt; + struct timeval now = ast_tvnow(); + struct ast_tm tmnow; + time_t beg_today; - gettimeofday(&now,NULL); - tt = now.tv_sec; - ast_localtime(&tt,&tmnow,timezone); + ast_localtime(&now, &tmnow, timezone); /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */ /* In any case, it saves not having to do ast_mktime() */ - beg_today = tt - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); + beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); if (beg_today < time) { /* Today */ res = wait_file(chan,ints, "digits/today",lang); @@ -7018,16 +7010,14 @@ static int ast_say_date_with_format_gr(struct ast_channel *chan, time_t time, co * language to say the date, with changes in what you say, depending * upon how recent the date is. XXX */ { - struct timeval now; - struct tm tmnow; - time_t beg_today, tt; + struct timeval now = ast_tvnow(); + struct ast_tm tmnow; + time_t beg_today; - gettimeofday(&now,NULL); - tt = now.tv_sec; - ast_localtime(&tt,&tmnow,timezone); + ast_localtime(&now, &tmnow, timezone); /* This might be slightly off, if we transcend a leap second, but never more off than 1 second */ /* In any case, it saves not having to do ast_mktime() */ - beg_today = tt - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); + beg_today = now.tv_sec - (tmnow.tm_hour * 3600) - (tmnow.tm_min * 60) - (tmnow.tm_sec); if (beg_today < time) { /* Today */ } else if ((beg_today - 86400) < time) { @@ -7320,10 +7310,11 @@ tslis /* Georgian syntax. e.g. "oriatas xuti tslis 5 noemberi". */ static int ast_say_date_ge(struct ast_channel *chan, time_t t, const char *ints, const char *lang) { - struct tm tm; + struct timeval tv = { t, 0 }; + struct ast_tm tm; char fn[256]; int res = 0; - ast_localtime(&t,&tm,NULL); + ast_localtime(&tv, &tm, NULL); if (!res) res = ast_say_number(chan, tm.tm_year + 1900, ints, lang, (char *) NULL); @@ -7359,10 +7350,11 @@ static int ast_say_date_ge(struct ast_channel *chan, time_t t, const char *ints, /* Georgian syntax. e.g. "otxi saati da eqvsi tsuti" */ static int ast_say_time_ge(struct ast_channel *chan, time_t t, const char *ints, const char *lang) { - struct tm tm; + struct timeval tv = { t, 0 }; + struct ast_tm tm; int res = 0; - ast_localtime(&t, &tm, NULL); + ast_localtime(&tv, &tm, NULL); res = ast_say_number(chan, tm.tm_hour, ints, lang, (char*)NULL); if (!res) { @@ -7390,10 +7382,11 @@ static int ast_say_time_ge(struct ast_channel *chan, time_t t, const char *ints, /* Georgian syntax. Say date, then say time. */ static int ast_say_datetime_ge(struct ast_channel *chan, time_t t, const char *ints, const char *lang) { - struct tm tm; + struct timeval tv = { t, 0 }; + struct ast_tm tm; int res = 0; - ast_localtime(&t, &tm, NULL); + ast_localtime(&tv, &tm, NULL); res = ast_say_date(chan, t, ints, lang); if (!res) ast_say_time(chan, t, ints, lang); @@ -7408,15 +7401,13 @@ static int ast_say_datetime_ge(struct ast_channel *chan, time_t t, const char *i static int ast_say_datetime_from_now_ge(struct ast_channel *chan, time_t t, const char *ints, const char *lang) { int res=0; - time_t nowt; int daydiff; - struct tm tm; - struct tm now; + struct ast_tm tm; + struct ast_tm now; + struct timeval tv = { t, 0 }, nowt = ast_tvnow(); char fn[256]; - time(&nowt); - - ast_localtime(&t, &tm, NULL); + ast_localtime(&tv, &tm, NULL); ast_localtime(&nowt, &now, NULL); daydiff = now.tm_yday - tm.tm_yday; if ((daydiff < 0) || (daydiff > 6)) { diff --git a/main/stdtime/localtime.c b/main/stdtime/localtime.c index 18cd3d7d8..4426feb97 100644 --- a/main/stdtime/localtime.c +++ b/main/stdtime/localtime.c @@ -180,25 +180,25 @@ static const char * getsecs P((const char * strp, long * secsp)); static const char * getoffset P((const char * strp, long * offsetp)); static const char * getrule P((const char * strp, struct rule * rulep)); static void gmtload P((struct state * sp)); -static void gmtsub P((const time_t * timep, long offset, - struct tm * tmp, const char * zone)); -static void localsub P((const time_t * timep, long offset, - struct tm * tmp, const char * zone)); +static void gmtsub P((const struct timeval * timep, long offset, + struct ast_tm * tmp, const char * zone)); +static void localsub P((const struct timeval * timep, long offset, + struct ast_tm * tmp, const char * zone)); static int increment_overflow P((int * number, int delta)); static int normalize_overflow P((int * tensptr, int * unitsptr, int base)); -static time_t time1 P((struct tm * tmp, - void(*funcp) P((const time_t *, - long, struct tm *, const char*)), +static time_t time1 P((struct ast_tm * tmp, + void(*funcp) P((const struct timeval *, + long, struct ast_tm *, const char *)), long offset, const char * zone)); -static time_t time2 P((struct tm *tmp, - void(*funcp) P((const time_t *, - long, struct tm*, const char*)), +static time_t time2 P((struct ast_tm *tmp, + void(*funcp) P((const struct timeval *, + long, struct ast_tm *, const char *)), long offset, int * okayp, const char * zone)); -static void timesub P((const time_t * timep, long offset, - const struct state * sp, struct tm * tmp)); -static int tmcomp P((const struct tm * atmp, - const struct tm * btmp)); +static void timesub P((const struct timeval * timep, long offset, + const struct state * sp, struct ast_tm *tmp)); +static int tmcomp P((const struct ast_tm *atmp, + const struct ast_tm * btmp)); static time_t transtime P((time_t janfirst, int year, const struct rule * rulep, long offset)); static int tzload P((const char * name, struct state * sp)); @@ -982,15 +982,16 @@ ast_tzset P((const char *name)) /*ARGSUSED*/ static void localsub(timep, offset, tmp, zone) -const time_t * const timep; +const struct timeval * const timep; const long offset; -struct tm * const tmp; +struct ast_tm * const tmp; const char * const zone; { register struct state * sp; register const struct ttinfo * ttisp; register int i; - const time_t t = *timep; + struct timeval t; + memcpy(&t, timep, sizeof(t)); sp = lclptr; /* Find the right zone record */ @@ -1019,7 +1020,7 @@ const char * const zone; gmtsub(timep, offset, tmp, zone); return; } - if (sp->timecnt == 0 || t < sp->ats[0]) { + if (sp->timecnt == 0 || t.tv_sec < sp->ats[0]) { i = 0; while (sp->ttis[i].tt_isdst) if (++i >= sp->typecnt) { @@ -1028,7 +1029,7 @@ const char * const zone; } } else { for (i = 1; i < sp->timecnt; ++i) - if (t < sp->ats[i]) + if (t.tv_sec < sp->ats[i]) break; i = sp->types[i - 1]; } @@ -1045,12 +1046,13 @@ const char * const zone; #ifdef TM_ZONE tmp->TM_ZONE = &sp->chars[ttisp->tt_abbrind]; #endif /* defined TM_ZONE */ + tmp->tm_usec = timep->tv_usec; } -struct tm * +struct ast_tm * ast_localtime(timep, p_tm, zone) -const time_t * const timep; -struct tm *p_tm; +const struct timeval * const timep; +struct ast_tm *p_tm; const char * const zone; { #ifdef _THREAD_SAFE @@ -1070,9 +1072,9 @@ const char * const zone; static void gmtsub(timep, offset, tmp, zone) -const time_t * const timep; +const struct timeval * const timep; const long offset; -struct tm * const tmp; +struct ast_tm * const tmp; const char * const zone; { #ifdef _THREAD_SAFE @@ -1104,10 +1106,10 @@ const char * const zone; static void timesub(timep, offset, sp, tmp) -const time_t * const timep; +const struct timeval * const timep; const long offset; register const struct state * const sp; -register struct tm * const tmp; +register struct ast_tm * const tmp; { register const struct lsinfo * lp; register long days; @@ -1124,8 +1126,8 @@ register struct tm * const tmp; i = (sp == NULL) ? 0 : sp->leapcnt; while (--i >= 0) { lp = &sp->lsis[i]; - if (*timep >= lp->ls_trans) { - if (*timep == lp->ls_trans) { + if (timep->tv_sec >= lp->ls_trans) { + if (timep->tv_sec == lp->ls_trans) { hit = ((i == 0 && lp->ls_corr > 0) || lp->ls_corr > sp->lsis[i - 1].ls_corr); if (hit) @@ -1142,10 +1144,10 @@ register struct tm * const tmp; break; } } - days = *timep / SECSPERDAY; - rem = *timep % SECSPERDAY; + days = timep->tv_sec / SECSPERDAY; + rem = timep->tv_sec % SECSPERDAY; #ifdef mc68k - if (*timep == 0x80000000) { + if (timep->tv_sec == 0x80000000) { /* ** A 3B1 muffs the division on the most negative number. */ @@ -1196,28 +1198,16 @@ register struct tm * const tmp; #ifdef TM_GMTOFF tmp->TM_GMTOFF = offset; #endif /* defined TM_GMTOFF */ + tmp->tm_usec = timep->tv_usec; } char * -ast_ctime(timep) -const time_t * const timep; -{ -/* -** Section 4.12.3.2 of X3.159-1989 requires that -** The ctime funciton converts the calendar time pointed to by timer -** to local time in the form of a string. It is equivalent to -** asctime(localtime(timer)) -*/ - return asctime(localtime(timep)); -} - -char * -ast_ctime_r(timep, buf) -const time_t * const timep; +ast_ctime(timep, buf) +const struct timeval * const timep; char *buf; { - struct tm tm; - return asctime_r(ast_localtime(timep, &tm, NULL), buf); + struct ast_tm tm; + return asctime_r((struct tm *)ast_localtime(timep, &tm, NULL), buf); } /* @@ -1267,8 +1257,8 @@ const int base; static int tmcomp(atmp, btmp) -register const struct tm * const atmp; -register const struct tm * const btmp; +register const struct ast_tm * const atmp; +register const struct ast_tm * const btmp; { register int result; @@ -1283,8 +1273,8 @@ register const struct tm * const btmp; static time_t time2(tmp, funcp, offset, okayp, zone) -struct tm * const tmp; -void (* const funcp) P((const time_t*, long, struct tm*, const char*)); +struct ast_tm * const tmp; +void (* const funcp) P((const struct timeval *, long, struct ast_tm*, const char*)); const long offset; int * const okayp; const char * const zone; @@ -1294,9 +1284,9 @@ const char * const zone; register int bits; register int i, j ; register int saved_seconds; - time_t newt; - time_t t; - struct tm yourtm, mytm; + struct timeval newt = { 0, 0 }; + struct timeval t = { 0, 0 }; + struct ast_tm yourtm, mytm; *okayp = FALSE; yourtm = *tmp; @@ -1364,7 +1354,7 @@ const char * const zone; ** assuming two's complement arithmetic. ** If time_t is unsigned, then (1 << bits) is just above the median. */ - t = TYPE_SIGNED(time_t) ? 0 : (((time_t) 1) << bits); + t.tv_sec = 0; for ( ; ; ) { (*funcp)(&t, offset, &mytm, zone); dir = tmcomp(&mytm, &yourtm); @@ -1372,10 +1362,10 @@ const char * const zone; if (bits-- < 0) return WRONG; if (bits < 0) - --t; /* may be needed if new t is minimal */ + --t.tv_sec; /* may be needed if new t is minimal */ else if (dir > 0) - t -= ((time_t) 1) << bits; - else t += ((time_t) 1) << bits; + t.tv_sec -= ((time_t) 1) << bits; + else t.tv_sec += ((time_t) 1) << bits; continue; } if (yourtm.tm_isdst < 0 || mytm.tm_isdst == yourtm.tm_isdst) @@ -1400,7 +1390,7 @@ const char * const zone; for (j = sp->typecnt - 1; j >= 0; --j) { if (sp->ttis[j].tt_isdst == yourtm.tm_isdst) continue; - newt = t + sp->ttis[j].tt_gmtoff - + newt.tv_sec = t.tv_sec + sp->ttis[j].tt_gmtoff - sp->ttis[i].tt_gmtoff; (*funcp)(&newt, offset, &mytm, zone); if (tmcomp(&mytm, &yourtm) != 0) @@ -1417,19 +1407,19 @@ const char * const zone; return WRONG; } label: - newt = t + saved_seconds; - if ((newt < t) != (saved_seconds < 0)) + newt.tv_sec = t.tv_sec + saved_seconds; + if ((newt.tv_sec < t.tv_sec) != (saved_seconds < 0)) return WRONG; - t = newt; + t.tv_sec = newt.tv_sec; (*funcp)(&t, offset, tmp, zone); *okayp = TRUE; - return t; + return t.tv_sec; } static time_t time1(tmp, funcp, offset, zone) -struct tm * const tmp; -void (* const funcp) P((const time_t *, long, struct tm *, const char*)); +struct ast_tm * const tmp; +void (* const funcp) P((const struct timeval *, long, struct ast_tm *, const char*)); const long offset; const char * const zone; { @@ -1489,7 +1479,7 @@ const char * const zone; time_t ast_mktime(tmp,zone) -struct tm * const tmp; +struct ast_tm * const tmp; const char * const zone; { time_t mktime_return_value; @@ -1504,3 +1494,62 @@ const char * const zone; return(mktime_return_value); } +int ast_strftime(char *buf, size_t len, const char *tmp, const struct ast_tm *tm) +{ + size_t fmtlen = strlen(tmp) + 1; + char *format = ast_calloc(1, fmtlen), *fptr = format, *newfmt; + int decimals = -1, i, res; + long fraction; + + if (!format) + return -1; + for (; *tmp; tmp++) { + if (*tmp == '%') { + switch (tmp[1]) { + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + if (tmp[2] != 'q') + goto defcase; + decimals = tmp[1] - '0'; + tmp++; + /* Fall through */ + case 'q': /* Milliseconds */ + if (decimals == -1) + decimals = 3; + + /* Juggle some memory to fit the item */ + newfmt = ast_realloc(format, fmtlen + decimals); + if (!newfmt) { + ast_free(format); + return -1; + } + fptr = fptr - format + newfmt; + format = newfmt; + fmtlen += decimals; + + /* Reduce the fraction of time to the accuracy needed */ + for (i = 6, fraction = tm->tm_usec; i > decimals; i--) + fraction /= 10; + fptr += sprintf(fptr, "%0*ld", decimals, fraction); + + /* Reset, in case more than one 'q' specifier exists */ + decimals = -1; + tmp++; + break; + default: + goto defcase; + } + } else +defcase: *fptr++ = *tmp; + } + *fptr = '\0'; +#undef strftime + res = (int)strftime(buf, len, format, (struct tm *)tm); + ast_free(format); + return res; +} + diff --git a/main/utils.c b/main/utils.c index 65139356d..d719837af 100644 --- a/main/utils.c +++ b/main/utils.c @@ -973,6 +973,33 @@ int ast_atomic_fetchadd_int_slow(volatile int *p, int v) return ret; } +/*! \brief + * get values from config variables. + */ +int ast_get_timeval(const char *src, struct timeval *dst, struct timeval _default, int *consumed) +{ + long double dtv = 0.0; + int scanned; + + if (dst == NULL) + return -1; + + *dst = _default; + + if (ast_strlen_zero(src)) + return -1; + + /* only integer at the moment, but one day we could accept more formats */ + if (sscanf(src, "%Lf%n", &dtv, &scanned) > 0) { + dst->tv_sec = dtv; + dst->tv_usec = (dtv - dst->tv_sec) * 1000000.0; + if (consumed) + *consumed = scanned; + return 0; + } else + return -1; +} + /*! \brief * get values from config variables. */ -- cgit v1.2.3