Fixed uptime output formatting to be less verbose.

This commit is contained in:
Jan Vidar Krey 2009-03-06 00:46:45 +01:00
parent c02c45f2d0
commit 6511761991
1 changed files with 8 additions and 36 deletions

View File

@ -83,34 +83,21 @@ static int command_uptime(struct user* user, const char* message)
{ {
struct adc_message* command; struct adc_message* command;
char tmp[128]; char tmp[128];
size_t w;
size_t d; size_t d;
size_t h; size_t h;
size_t m; size_t m;
size_t s;
size_t D = (size_t) difftime(time(0), user->hub->tm_started); size_t D = (size_t) difftime(time(0), user->hub->tm_started);
w = D / (7 * 24 * 3600);
D = D % (7 * 24 * 3600);
d = D / (24 * 3600); d = D / (24 * 3600);
D = D % (24 * 3600); D = D % (24 * 3600);
h = D / 3600; h = D / 3600;
D = D % 3600; D = D % 3600;
m = D / 60; m = D / 60;
s = D % 60;
tmp[0] = 0; tmp[0] = 0;
strcat(tmp, "*** Uptime: "); strcat(tmp, "*** Uptime: ");
if (w) if (d)
{
strcat(tmp, uhub_itoa((int) w));
strcat(tmp, " week");
if (w != 1) strcat(tmp, "s");
strcat(tmp, ", ");
}
if (w || d)
{ {
strcat(tmp, uhub_itoa((int) d)); strcat(tmp, uhub_itoa((int) d));
strcat(tmp, " day"); strcat(tmp, " day");
@ -118,26 +105,11 @@ static int command_uptime(struct user* user, const char* message)
strcat(tmp, ", "); strcat(tmp, ", ");
} }
if (w || d || h) if (h < 10) strcat(tmp, "0");
{
strcat(tmp, uhub_itoa((int) h)); strcat(tmp, uhub_itoa((int) h));
strcat(tmp, " hour"); strcat(tmp, ":");
if (h != 1) strcat(tmp, "s"); if (m < 10) strcat(tmp, "0");
strcat(tmp, ", ");
}
if (w || d || h || m)
{
strcat(tmp, uhub_itoa((int) m)); strcat(tmp, uhub_itoa((int) m));
strcat(tmp, " minute");
if (m != 1) strcat(tmp, "s");
strcat(tmp, ", and ");
}
strcat(tmp, uhub_itoa((int) s));
strcat(tmp, " second");
if (s != 1) strcat(tmp, "s");
strcat(tmp, ".");
char* buffer = adc_msg_escape(tmp); char* buffer = adc_msg_escape(tmp);
command = adc_msg_construct(ADC_CMD_IMSG, strlen(buffer) + 6); command = adc_msg_construct(ADC_CMD_IMSG, strlen(buffer) + 6);