/// <summary> /// Returns whether or not the appointment recurs on the date in question. /// </summary> /// <param name="date"></param> /// <returns></returns> public override Boolean IsOccuringOn(Date date) { // Put a safeguard in case this code has bugs. int endlessLoopCounter = 0; const int endlessLoopTerminator = 10000; // Loop through each occurrence; starting with the first occurrence start. var occurenceStartTime = new DateTime(base.GetStartTime()); while (occurenceStartTime.CompareTo(mNotToExceedDateTime) <= 0) { // Calculate the occurrence end based on the duration. var occurenceEndTime = new DateTime(occurenceStartTime); occurenceEndTime.AddTime(0, base.GetDurationMinutes()); // Evaluate if the input date is within the occurrence window. if (date.IsBetween(occurenceStartTime.GetDate(), occurenceEndTime.GetDate())) { return(true); } endlessLoopCounter++; if (endlessLoopCounter > endlessLoopTerminator) { throw new ApplicationException("Infinite loop detected."); } occurenceStartTime.AddTime(mPeriodHours, 0); } return(false); }
public void ConstructorNotToExceedDateTimeAliasingTest() { var occurs = new DateTime(new Date(1, Date.Month.JANUARY, 2000), 0, 0); var notToExceedDateTime = new Diary.DateTime(occurs); var occurenceDate = new Date(2, Date.Month.JANUARY, 2000); var builder = new PeriodicAppointmentBuilder(); builder.SetOccurs(occurs); builder.SetPeriodHours(24); builder.SetNotToExceedDateTime(notToExceedDateTime); var appointment = (PeriodicAppointment)builder.Build(); var expected = false; var actual = appointment.IsOccuringOn(occurenceDate); Assert.AreEqual(expected, actual, "Original"); notToExceedDateTime.AddTime(100, 0); actual = appointment.IsOccuringOn(occurenceDate); Assert.AreEqual(expected, actual, "After"); }
/// <summary> /// Returns the appointment end time. /// </summary> /// <returns></returns> public DateTime GetEndTime() { var endTime = new DateTime(mStarts); endTime.AddTime(0, mDurationMinutes); return(endTime); }
public void AddTimeTest() { var dateTime = new Diary.DateTime(new Date(1, Date.Month.JANUARY, 1900), 0, 0); dateTime.AddTime(1, 1); Assert.AreEqual("1900-01-01 01:01", Helper.ToString(dateTime)); }
public void ConstructorAliasingTest() { var builder = new AppointmentBuilder(); var dateTime = new Diary.DateTime(); var appointment = (Appointment)builder.SetOccurs(dateTime).Build(); var expected = 0; var actual = appointment.GetStartTime().GetMinutes(); Assert.AreEqual(expected, actual, "Original"); dateTime.AddTime(0, 1); actual = appointment.GetStartTime().GetMinutes(); Assert.AreEqual(expected, actual, "After"); }