time.c~

MudOSa4DGD/mudlib/dgd/lib/sys/efun/time.c~ · 1.3 KB

From the archive MudOSa4DGD-30.06.98.tar.gz

Download the archive   « Back to the archive contents

/*
 * 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";
    }
  }
}

Site Stats

Snippets: 1791
Codebases: 571