/* ValidBooking
 *----------------------------------------------------------------
 * Return true iff the appointment slot on day between startTime
 * and endTime is not used by other appointments.
 * REVISED version.  Doesn't mess up when the end time of one
 * appointment = the start time of the next. 
*/
boolean
ValidBooking(Calendar *C, Workday day, ClockTime startTime, ClockTime endTime)
{
    /* We're guaranteed to have both of these because of the virtual
       appointments. */
    ApptNode *currAppt = C->WorkWeek[day];
    ApptNode *nextAppt = currAppt->next;

    /* Postcondition : nextAppt points to an appointment which starts
       later than startTime.*/
    while((!TimeGreaterThan(nextAppt->appt.startTime, endTime)) &&
          !TimeEqual(nextAppt->appt.startTime, endTime))
    {
        currAppt = nextAppt;
        nextAppt = nextAppt->next;
    }

    /* Return true if the new appointment fits.*/
    return ((TimeGreaterThan(startTime, currAppt->appt.endTime) ||
             TimeEqual(startTime, currAppt->appt.endTime)) &&
            (TimeGreaterThan(nextAppt->appt.startTime, endTime) ||
             TimeEqual(nextAppt->appt.startTime, endTime)));
}
