/// <summary> /// Derives the adjusted date if not already provided. /// </summary> /// <param name="baseDate">The base date is settlement is relative.</param> /// <param name="adjustableOrAdjustedDate">this may contain the adjustedDate, an unadjustedDate and business Centre</param> /// <param name="cache">THe cache if the business calendar has not already been calculated.</param> /// <param name="nameSpace">The client nameSpace</param> /// <param name="businessCalendar">THe business calendar must be provided, no namespace is required and can be null</param> /// <returns></returns> public static DateTime?GetAdjustedDate(ICoreCache cache, string nameSpace, IBusinessCalendar businessCalendar, DateTime?baseDate, AdjustableOrRelativeDate adjustableOrAdjustedDate) { if (adjustableOrAdjustedDate.Item is AdjustableDate date) { return(GetAdjustedDate(cache, nameSpace, businessCalendar, date)); } if (adjustableOrAdjustedDate.Item is RelativeDateOffset relativeDate && baseDate != null) { return(GetAdjustedDate(cache, nameSpace, businessCalendar, baseDate, relativeDate)); } return(null); }
/// <summary> /// Converts to an adjustable date type. /// </summary> /// <param name="cache"> </param> /// <param name="referenceDate"></param> /// <param name="adjustableOrRelativeDate"></param> /// <param name="nameSpace"></param> /// <returns></returns> public static DateTime ToAdjustedDate(ICoreCache cache, DateTime?referenceDate, AdjustableOrRelativeDate adjustableOrRelativeDate, string nameSpace) { if (null == adjustableOrRelativeDate.Item) { throw new ArgumentNullException(nameof(adjustableOrRelativeDate)); } // handle BusinessDatConventionEnum is NONE as a special case, since there might be no business centers provided. // var adjustableDate = adjustableOrRelativeDate.Item as AdjustableDate; var relativeDate = adjustableOrRelativeDate.Item as RelativeDateOffset; var result = new DateTime(); if (adjustableDate != null) { var calendar = BusinessCenterHelper.ToBusinessCalendar(cache, adjustableDate.dateAdjustments.businessCenters, nameSpace); return(ToAdjustedDate(calendar, adjustableDate)); } if (relativeDate != null) { var calendar = BusinessCenterHelper.ToBusinessCalendar(cache, relativeDate.businessCenters, nameSpace); if (referenceDate != null) { return(ToAdjustedDate(calendar, (DateTime)referenceDate, relativeDate)); } } return(result); }