diff options
author | Joshua Colp <jcolp@digium.com> | 2016-03-08 11:29:45 -0600 |
---|---|---|
committer | Gerrit Code Review <gerrit2@gerrit.digium.api> | 2016-03-08 11:29:45 -0600 |
commit | 5cf2226e0123f7cfa40345098223f2fa1303454b (patch) | |
tree | 6a0acbbd9c7f696e36a69fe4d791823d0eb866e8 /res/res_config_ldap.c | |
parent | 760444a1f571b038fc0402a0d3588a477304d188 (diff) | |
parent | 0ec9fe54219f8ad8a1e2c6f0a17843dcf08b7451 (diff) |
Merge "main/cli.c: Refactor function to print seconds formatted"
Diffstat (limited to 'res/res_config_ldap.c')
-rw-r--r-- | res/res_config_ldap.c | 25 |
1 files changed, 5 insertions, 20 deletions
diff --git a/res/res_config_ldap.c b/res/res_config_ldap.c index 95eae29c1..845427379 100644 --- a/res/res_config_ldap.c +++ b/res/res_config_ldap.c @@ -1837,7 +1837,9 @@ static int ldap_reconnect(void) */ static char *realtime_ldap_status(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { - char status[256], credentials[100] = ""; + char status[256]; + char credentials[100] = ""; + char buf[362]; /* 256+100+" for "+NULL */ int ctimesec = time(NULL) - connect_time; switch (cmd) { @@ -1860,25 +1862,8 @@ static char *realtime_ldap_status(struct ast_cli_entry *e, int cmd, struct ast_c if (!ast_strlen_zero(user)) snprintf(credentials, sizeof(credentials), " with username %s", user); - if (ctimesec > 31536000) { - ast_cli(a->fd, "%s%s for %d years, %d days, %d hours, %d minutes, %d seconds.\n", - status, credentials, ctimesec / 31536000, - (ctimesec % 31536000) / 86400, (ctimesec % 86400) / 3600, - (ctimesec % 3600) / 60, ctimesec % 60); - } else if (ctimesec > 86400) { - ast_cli(a->fd, "%s%s for %d days, %d hours, %d minutes, %d seconds.\n", - status, credentials, ctimesec / 86400, (ctimesec % 86400) / 3600, - (ctimesec % 3600) / 60, ctimesec % 60); - } else if (ctimesec > 3600) { - ast_cli(a->fd, "%s%s for %d hours, %d minutes, %d seconds.\n", - status, credentials, ctimesec / 3600, (ctimesec % 3600) / 60, - ctimesec % 60); - } else if (ctimesec > 60) { - ast_cli(a->fd, "%s%s for %d minutes, %d seconds.\n", status, credentials, - ctimesec / 60, ctimesec % 60); - } else { - ast_cli(a->fd, "%s%s for %d seconds.\n", status, credentials, ctimesec); - } + snprintf(buf, sizeof(buf), "%s%s for ", status, credentials); + ast_cli_print_timestr_fromseconds(a->fd, ctimesec, buf); return CLI_SUCCESS; } |