public static Period Sum(this Period thisPeriod, Period periodToAdd) { if (periodToAdd == null) { throw new ArgumentNullException("periodToAdd"); } if (thisPeriod.period != periodToAdd.period) { string message = String.Format("Intervals must be of the same period type and they are not. Interval1 : {0}, interval2 : {1}", thisPeriod.ToString(), periodToAdd.ToString()); throw new Exception(message); } string newPeriodMultiplier = (thisPeriod.GetPeriodMultiplier() + periodToAdd.GetPeriodMultiplier()).ToString(CultureInfo.InvariantCulture); var sum = new Period { period = thisPeriod.period, periodMultiplier = newPeriodMultiplier }; return(sum); }
public static Period Subtract(this Period thisPeriod, Period periodToSubtract) { if (periodToSubtract == null) { throw new ArgumentNullException("periodToSubtract"); } if (thisPeriod.period != periodToSubtract.period) { string message = String.Format("Periods must be of the same period type. This period '{0}', period to subtract '{1}'", thisPeriod.ToString(), periodToSubtract.ToString()); throw new ArgumentException(message, "periodToSubtract"); } double multiplier = thisPeriod.GetPeriodMultiplier() - periodToSubtract.GetPeriodMultiplier(); var difference = new Period { period = thisPeriod.period, periodMultiplier = multiplier.ToString(CultureInfo.InvariantCulture) }; return(difference); }
public static string ToString(Period interval) { return(interval.ToString()); }