public void Addition_Subtraction(int leftDays, long leftNanos, int rightDays, long rightNanos, int resultDays, long resultNanos) { var left = new Duration(leftDays, leftNanos); var right = new Duration(rightDays, rightNanos); var result = new Duration(resultDays, resultNanos); Assert.AreEqual(result, left + right); Assert.AreEqual(result, left.Plus(right)); Assert.AreEqual(result, Duration.Add(left, right)); Assert.AreEqual(left, result - right); Assert.AreEqual(left, result.Minus(right)); Assert.AreEqual(left, Duration.Subtract(result, right)); }
public void ResolveEnd() { if (Start.HasValue && !EndOfDuration.HasValue) { EndOfDuration = Duration.Add(Start.Value); } if (Finish.HasValue && EndOfDuration > Finish) { EndOfDuration = Finish; } if (Start.HasValue && !Next.HasValue) { Next = EndOfDuration; } }
public void ResolveEnd() { if (Start.HasValue && !EndOfDuration.HasValue) { EndOfDuration = Duration.Add(Start.Value); Logger.Current.Debug("times.interval", () => String.Format("stabilize: end_of_duration = {0}", EndOfDuration)); } if (Finish.HasValue && EndOfDuration > Finish) { EndOfDuration = Finish; Logger.Current.Debug("times.interval", () => String.Format("stabilize: end_of_duration reset to end: {0}", EndOfDuration)); } if (Start.HasValue && !Next.HasValue) { Next = EndOfDuration; Logger.Current.Debug("times.interval", () => String.Format("stabilize: next set to: {0}", Next)); } }
public void TestAddDuration() { // Arrange int inputSecondsOne = 2; int inputSecondsTwo = 30; int inputMinutesOne = 0; int inputMinutesTwo = 0; int inputHoursOne = 0; int inputHoursTwo = 0; int expected = 32; Duration durationOne = new Duration(inputHoursOne, inputMinutesOne, inputSecondsOne); Duration durationTwo = new Duration(inputHoursTwo, inputMinutesTwo, inputSecondsTwo); // Act durationOne.Add(durationTwo); var result = durationOne.totalSeconds; // Assert Assert.AreEqual(expected, result); }
public void When_Duration_Is_TimeSpan() { var duration = new Duration(TimeSpan.FromSeconds(24)); Assert.IsTrue(duration.HasTimeSpan); Assert.IsTrue(duration.Equals((object)new Duration(TimeSpan.FromSeconds(24)))); Assert.IsTrue(duration.Equals(new Duration(TimeSpan.FromSeconds(24)))); Assert.IsTrue(Duration.Equals(duration, new Duration(TimeSpan.FromSeconds(24)))); Assert.IsFalse(duration.Equals(null)); Assert.IsFalse(duration.Equals((object)Duration.Automatic)); Assert.IsFalse(duration.Equals(new Duration(TimeSpan.FromSeconds(30)))); Assert.IsFalse(Duration.Equals(duration, Duration.Forever)); Assert.AreEqual("00:00:24", duration.ToString()); Assert.AreEqual(1, duration.CompareTo(Duration.Automatic)); Assert.AreEqual(-1, duration.CompareTo(Duration.Forever)); Assert.AreEqual(0, Duration.Compare(duration, new Duration(TimeSpan.FromSeconds(24)))); Assert.AreEqual(new Duration(TimeSpan.FromSeconds(48)), duration.Add(new Duration(TimeSpan.FromSeconds(24)))); Assert.AreEqual(new Duration(TimeSpan.FromSeconds(1)), duration.Subtract(new Duration(TimeSpan.FromSeconds(23)))); }
public static Duration Add(Duration target, Duration duration) => target.Add(duration);
/** Find the current or next period containing date. Returns false if * no such period can be found. If allow_shift is true, the default, * then the interval may be shifted in time to find the period. */ public bool FindPeriod(Date date, bool allowShift = true) { Stabilize(date); if (Finish.HasValue && date > Finish) { Logger.Current.Debug("times.interval", () => String.Format("false: date [{0}] > finish [{1}]", date, Finish)); return(false); } if (!Start.HasValue) { throw new RuntimeError(RuntimeError.ErrorMessageDateIntervalIsImproperlyInitialized); } if (date < Start) { Logger.Current.Debug("times.interval", () => String.Format("false: date [{0}] < start [{1}]", date, Start)); return(false); } if (EndOfDuration.HasValue) { if (date < EndOfDuration) { Logger.Current.Debug("times.interval", () => String.Format("true: date [{0}] < end_of_duration [{1}]", date, EndOfDuration)); return(true); } } else { Logger.Current.Debug("times.interval", () => "false: there is no end_of_duration"); return(false); } // If we've reached here, it means the date does not fall into the current // interval, so we must seek another interval that does match -- unless we // pass by date in so doing, which means we shouldn't alter the current // period of the interval at all. Date scan = Start.Value; Date endOfScan = EndOfDuration.Value; Logger.Current.Debug("times.interval", () => String.Format("date = {0}", date)); Logger.Current.Debug("times.interval", () => String.Format("scan = {0}", scan)); Logger.Current.Debug("times.interval", () => String.Format("end_of_scan = {0}", endOfScan)); if (Finish.HasValue) { Logger.Current.Debug("times.interval", () => String.Format("finish = {0}", Finish)); } else { Logger.Current.Debug("times.interval", () => "finish is not set"); } while (date >= scan && (!Finish.HasValue || scan < Finish)) { if (date < endOfScan) { Start = scan; EndOfDuration = endOfScan; Next = null; Logger.Current.Debug("times.interval", () => String.Format("true: start = {0}", Start)); Logger.Current.Debug("times.interval", () => String.Format("true: end_of_duration = {0}", EndOfDuration)); ResolveEnd(); return(true); } else if (!allowShift) { break; } scan = Duration.Add(scan); endOfScan = Duration.Add(scan); Logger.Current.Debug("times.interval", () => String.Format("scan = {0}", scan)); Logger.Current.Debug("times.interval", () => String.Format("end_of_scan = {0}", endOfScan)); } Logger.Current.Debug("times.interval", () => "false: failed scan"); return(false); }
/// <summary> /// Method which adds element to playlist and calculates playlist duration /// </summary> /// <param name="musicFile">Element to add</param> public void Add(MusicFile musicFile) { musicFileList.Add(musicFile); Duration = Duration.Add(musicFile.Duration); PlaybackList.Items.Add(musicFile.PlaybackItem); }
public void Add(MusicFileViewModel musicFile) { musicFileList.Add(musicFile); Duration = Duration.Add(musicFile.Duration); }
/** Find the current or next period containing date. Returns false if * no such period can be found. If allow_shift is true, the default, * then the interval may be shifted in time to find the period. */ public bool FindPeriod(Date date, bool allowShift = true) { Stabilize(date); if (Finish.HasValue && date > Finish) { return(false); } if (!Start.HasValue) { throw new RuntimeError(RuntimeError.ErrorMessageDateIntervalIsImproperlyInitialized); } if (date < Start) { return(false); } if (EndOfDuration.HasValue) { if (date < EndOfDuration) { return(true); } } else { return(false); } // If we've reached here, it means the date does not fall into the current // interval, so we must seek another interval that does match -- unless we // pass by date in so doing, which means we shouldn't alter the current // period of the interval at all. Date scan = Start.Value; Date endOfScan = EndOfDuration.Value; while (date >= scan && (!Finish.HasValue || scan < Finish)) { if (date < endOfScan) { Start = scan; EndOfDuration = endOfScan; Next = null; ResolveEnd(); return(true); } else if (!allowShift) { break; } scan = Duration.Add(scan); endOfScan = Duration.Add(scan); } return(false); }