/*
* 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 and seconds. */
static varargs string format_time(int time, int lng) {
int days, hours, minutes, seconds, sz;
string ret, *arr;
/* find all elements */
seconds = time % 60;
minutes = (time / 60) % 60;
hours = (minutes / 60) % 60;
days = hours / 24;
/* find array to implode */
arr = ({ });
if (days > 0 || lng) {
/* "X days" */
if (days > 1)
arr += ({ (string)days+" days" });
else
arr += ({ (string)days+" day" });
}
if (hours > 0 || lng) {
/* "X hours" */
if (hours > 1)
arr += ({ (string)hours+" hours" });
else
arr += ({ (string)hours+" hour" });
}
if (minutes > 0 || lng) {
/* "X minutes" */
if (minutes > 1)
arr += ({ (string)minutes+" minutes" });
else
arr += ({ (string)minutes+" minute" });
}
if (seconds > 0 || lng) {
/* "X minutes" */
if (seconds > 1)
arr += ({ (string)seconds+" seconds" });
else
arr += ({ (string)seconds+" second" });
}
/* implode into "X, Y and Z". */
if ((sz=::sizeof(arr)) > 2) {
ret = implode(arr[..sz-2], ", ");
ret += " and "+arr[sz-1];
}
else {
ret = implode(arr, " and ");
}
return ret;
}