diff options
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/wee-command.c | 39 | ||||
-rw-r--r-- | src/core/wee-util.c | 24 | ||||
-rw-r--r-- | src/core/wee-util.h | 2 |
3 files changed, 43 insertions, 22 deletions
diff --git a/src/core/wee-command.c b/src/core/wee-command.c index dee891cf7..2ed98a250 100644 --- a/src/core/wee-command.c +++ b/src/core/wee-command.c @@ -6185,8 +6185,7 @@ COMMAND_CALLBACK(upgrade) COMMAND_CALLBACK(uptime) { - time_t running_time; - int day, hour, min, sec; + int days, hours, minutes, seconds; char string[512]; /* make C compiler happy */ @@ -6194,21 +6193,17 @@ COMMAND_CALLBACK(uptime) (void) data; (void) argv_eol; - running_time = time (NULL) - weechat_first_start_time; - day = running_time / (60 * 60 * 24); - hour = (running_time % (60 * 60 * 24)) / (60 * 60); - min = ((running_time % (60 * 60 * 24)) % (60 * 60)) / 60; - sec = ((running_time % (60 * 60 * 24)) % (60 * 60)) % 60; + util_get_uptime (NULL, &days, &hours, &minutes, &seconds); if ((argc >= 2) && (string_strcasecmp (argv[1], "-o") == 0)) { snprintf (string, sizeof (string), "WeeChat uptime: %d %s %02d:%02d:%02d, started on %s", - day, - (day != 1) ? "days" : "day", - hour, - min, - sec, + days, + (days != 1) ? "days" : "day", + hours, + minutes, + seconds, ctime (&weechat_first_start_time)); string[strlen (string) - 1] = '\0'; (void) input_data (buffer, string); @@ -6218,11 +6213,11 @@ COMMAND_CALLBACK(uptime) snprintf (string, sizeof (string), /* TRANSLATORS: "%s" after "started on" is a date */ _("WeeChat uptime: %d %s %02d:%02d:%02d, started on %s"), - day, - NG_("day", "days", day), - hour, - min, - sec, + days, + NG_("day", "days", days), + hours, + minutes, + seconds, util_get_time_string (&weechat_first_start_time)); (void) input_data (buffer, string); } @@ -6234,17 +6229,17 @@ COMMAND_CALLBACK(uptime) "%s%02d%s:%s%02d%s:%s%02d%s, " "started on %s%s"), GUI_COLOR(GUI_COLOR_CHAT_BUFFER), - day, + days, GUI_COLOR(GUI_COLOR_CHAT), - NG_("day", "days", day), + NG_("day", "days", days), GUI_COLOR(GUI_COLOR_CHAT_BUFFER), - hour, + hours, GUI_COLOR(GUI_COLOR_CHAT), GUI_COLOR(GUI_COLOR_CHAT_BUFFER), - min, + minutes, GUI_COLOR(GUI_COLOR_CHAT), GUI_COLOR(GUI_COLOR_CHAT_BUFFER), - sec, + seconds, GUI_COLOR(GUI_COLOR_CHAT), GUI_COLOR(GUI_COLOR_CHAT_BUFFER), util_get_time_string (&weechat_first_start_time)); diff --git a/src/core/wee-util.c b/src/core/wee-util.c index 0dccb1861..4716956f2 100644 --- a/src/core/wee-util.c +++ b/src/core/wee-util.c @@ -766,3 +766,27 @@ util_version_number (const char *version) return (version_int[0] << 24) | (version_int[1] << 16) | (version_int[2] << 8) | version_int[3]; } + +/* + * Return uptime as number of days, hours, minutes, seconds. + */ + +void +util_get_uptime (time_t *total_seconds, int *days, + int *hours, int *minutes, int *seconds) +{ + time_t running_time; + + running_time = time (NULL) - weechat_first_start_time; + + if (total_seconds) + *total_seconds = running_time; + if (days) + *days = running_time / (60 * 60 * 24); + if (hours) + *hours = (running_time % (60 * 60 * 24)) / (60 * 60); + if (minutes) + *minutes = ((running_time % (60 * 60 * 24)) % (60 * 60)) / 60; + if (seconds) + *seconds = ((running_time % (60 * 60 * 24)) % (60 * 60)) % 60; +} diff --git a/src/core/wee-util.h b/src/core/wee-util.h index 47a24575f..e03c7a815 100644 --- a/src/core/wee-util.h +++ b/src/core/wee-util.h @@ -52,5 +52,7 @@ extern char *util_search_full_lib_name (const char *filename, const char *sys_directory); extern char *util_file_get_content (const char *filename); extern int util_version_number (const char *version); +extern void util_get_uptime (time_t *total_seconds, int *days, + int *hours, int *minutes, int *seconds); #endif /* WEECHAT_UTIL_H */ |