/** Converts an integer number of seconds to a string giving the
 * length of the time period in days, hours, minutes and seconds.
 */
string int_to_time(int x) {
  string buf="";
  int y;

  y = x/(60*60*24);   // days
  x -= y*60*60*24;
  if (y > 0)
    buf += (string)y+" day"+(y==1?"":"s")+", ";

  y = x/(60*60);   // hours
  x -= y*60*60;
  if (y > 0)
    buf += (string)y+" hour"+(y==1?"":"s")+", ";

  y = x/(60);      // minutes
  x -= y*60;
  if( y > 0 )
  buf += (string)y+" minute"+(y==1?"":"s")+" and ";
  
  buf += (string)x+" second"+(x==1?"":"s");
  return buf;
}
