mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-29 18:19:30 +00:00
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
This commit is contained in:
@@ -139,7 +139,9 @@ static char *handle_cdr_pgsql_status(struct ast_cli_entry *e, int cmd, struct as
|
||||
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 (pgdbport) {
|
||||
@@ -154,17 +156,10 @@ static char *handle_cdr_pgsql_status(struct ast_cli_entry *e, int cmd, struct as
|
||||
if (table && *table) {
|
||||
snprintf(status2, 99, " using table %s", table);
|
||||
}
|
||||
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 {
|
||||
|
Reference in New Issue
Block a user