/*
* time.c
*
* Time topics
*
* (C) Frank Schmidt, Jesus@NorseMUD
*
*/
#ifdef MUDOS_UPTIME
/* return uptime of the driver */
static int uptime() {
return time() - DRIVER->query_reboot_time();
}
#endif
#ifdef MUDOS_REBOOT_TIME
/* return last reboot time of the driver */
static int reboot_time() {
return DRIVER->query_reboot_time();
}
#endif
/* convert <time> to days, hours, minutes, seconds. */
static varargs string format_time(int time, int short) {
int days, hours, minutes, seconds;
seconds = time % 60;
minutes = (time / 60) % 60;
hours = (minutes / 60) % 60;
days = hours / 24;
if (!short) {
/* show longest */
return
(string)days+" days, "+
(string)hours+" hours, "+
(string)minutes+" minutes and "+
(string)seconds+" seconds";
}
else {
/* show shortest */
string ret;
ret = "";
if (days) ret = (string)days+" days";
if (hours) {
if (days) {
if (!minutes && !seconds)
ret += " and ";
else
ret += ", ";
}
ret += (string)hours+" hours";
}
if (minutes) {
if (days || hours) {
if (!seconds)
ret += " and ";
else
ret += ", ";
}
ret += (string)minutes+" minutes";
}
if (seconds) {
if (days || hours || minutes)
ret += " and ";
ret += (string)seconds+" seconds";
}
}
}