public static Dictionary <DateElement, int> ToLookbackDictionary(this string lookback) { var result = new Dictionary <DateElement, int>(); var matches = ParseLookback(lookback); if (matches.Count <= 0) { throw new ArgumentException("Lookback string is not valid", nameof(lookback)); } foreach (Match match in matches) { var elementDirection = GetDirection(match.Groups[1].Value.Trim()); var elementValueStr = match.Groups[2].Value.Trim(); var elementValueType = match.Groups[3].Value.Trim(); if (!int.TryParse(elementValueStr, out var elementValue)) { elementValue = 0; } if (elementDirection.Equals("-")) { elementValue = elementValue * -1; } var e = DateElement.Parse(elementValueType); result.Add(e, elementValue); } return(result); }
public static System.DateTime ApplyOffset(this System.DateTime date, string @type, int amount) { return(DateElement.Parse(type).Element.Add(date, amount)); }