summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorRodrigo Ramírez Norambuena <a@rodrigoramirez.com>2016-02-18 01:58:01 -0300
committerRodrigo Ramírez Norambuena <a@rodrigoramirez.com>2016-03-07 03:42:18 -0300
commit0ec9fe54219f8ad8a1e2c6f0a17843dcf08b7451 (patch)
treec2607814027ff8a7c5c9c88b49542948003ec819 /addons
parent62282bb8ce15e3e70b3e2fd79834c02911b5f8ff (diff)
main/cli.c: Refactor function to print seconds formatted
Refactor and created function ast_cli_print_timestr_fromseconds to print seconds formatted: year(s) week(s) day(s) hour(s) second(s) This function now is used in addons/cdr_mysql.c,cdr_pgsql.c, main/cli.c, res_config_ldap.c, res_config_pgsql.c. Change-Id: Ibeb8634102cd11d3f8623398b279cb731bcde36c
Diffstat (limited to 'addons')
-rw-r--r--addons/cdr_mysql.c19
1 files changed, 7 insertions, 12 deletions
diff --git a/addons/cdr_mysql.c b/addons/cdr_mysql.c
index d55f9e035..9873395c2 100644
--- a/addons/cdr_mysql.c
+++ b/addons/cdr_mysql.c
@@ -119,7 +119,9 @@ static char *handle_cli_cdr_mysql_status(struct ast_cli_entry *e, int cmd, struc
return CLI_SHOWUSAGE;
if (connected) {
- char status[256], status2[100] = "";
+ char status[256];
+ char status2[100] = "";
+ char buf[362]; /* 256+100+" for "+NULL */
int ctime = time(NULL) - connect_time;
if (dbport)
snprintf(status, 255, "Connected to %s@%s, port %d", ast_str_buffer(dbname), ast_str_buffer(hostname), dbport);
@@ -132,17 +134,10 @@ static char *handle_cli_cdr_mysql_status(struct ast_cli_entry *e, int cmd, struc
snprintf(status2, 99, " with username %s", ast_str_buffer(dbuser));
if (ast_str_strlen(dbtable))
snprintf(status2, 99, " using table %s", ast_str_buffer(dbtable));
- if (ctime > 31536000) {
- ast_cli(a->fd, "%s%s for %d years, %d days, %d hours, %d minutes, %d seconds.\n", status, status2, ctime / 31536000, (ctime % 31536000) / 86400, (ctime % 86400) / 3600, (ctime % 3600) / 60, ctime % 60);
- } else if (ctime > 86400) {
- ast_cli(a->fd, "%s%s for %d days, %d hours, %d minutes, %d seconds.\n", status, status2, ctime / 86400, (ctime % 86400) / 3600, (ctime % 3600) / 60, ctime % 60);
- } else if (ctime > 3600) {
- ast_cli(a->fd, "%s%s for %d hours, %d minutes, %d seconds.\n", status, status2, ctime / 3600, (ctime % 3600) / 60, ctime % 60);
- } else if (ctime > 60) {
- ast_cli(a->fd, "%s%s for %d minutes, %d seconds.\n", status, status2, ctime / 60, ctime % 60);
- } else {
- ast_cli(a->fd, "%s%s for %d seconds.\n", status, status2, ctime);
- }
+
+ snprintf(buf, sizeof(buf), "%s%s for ", status, status2);
+ ast_cli_print_timestr_fromseconds(a->fd, ctime, buf);
+
if (records == totalrecords)
ast_cli(a->fd, " Wrote %d records since last restart.\n", totalrecords);
else