public void TestOriginalDuration() { TimeSpan testDur = TimeSpan.FromMinutes(10); TimeSpan changedDur = TimeSpan.FromMinutes(20); TalkScheduleItem item = new TalkScheduleItem { Duration = testDur }; Assert.AreEqual(item.Duration, testDur); Assert.AreEqual(item.OriginalDuration, testDur); Assert.IsTrue(item.GetDurationSeconds() == (int)testDur.TotalSeconds); item.Duration = changedDur; Assert.AreEqual(item.OriginalDuration, testDur); Assert.IsTrue(item.GetDurationSeconds() == (int)changedDur.TotalSeconds); }
/// <summary> /// Calculates the adapted talk duration for specified talk id /// </summary> /// <param name="itemId">Talk Id</param> /// <returns>Adapted time (or null if time is not adapted)</returns> public TimeSpan?CalculateAdaptedDuration(int itemId) { TalkScheduleItem talk = _scheduleService.GetTalkScheduleItem(itemId); if (talk != null) { EnsureMeetingStartTimeIsSet(talk); if (_meetingStartTimeUtc != null) { AdaptiveMode adaptiveMode = GetAdaptiveMode(); if (adaptiveMode != AdaptiveMode.None) { if (talk.AllowAdaptive) { var talkPlannedStartTime = CalculatePlannedStartTimeOfItem(talk); var talkActualStartTime = DateTime.UtcNow; var deviation = talkActualStartTime - talkPlannedStartTime; if (DeviationWithinRange(deviation)) { if (adaptiveMode == AdaptiveMode.TwoWay || talkPlannedStartTime < talkActualStartTime) { TimeSpan remainingAdaptiveTime = CalculateRemainingAdaptiveTime(talk); double fractionToApplyToThisTalk = talk.GetDurationSeconds() / remainingAdaptiveTime.TotalSeconds; double secondsToApply = deviation.TotalSeconds * fractionToApplyToThisTalk; return(talk.OriginalDuration.Subtract(TimeSpan.FromSeconds(secondsToApply))); } } } } } } return(null); }