internal static RecurrenceInfo GetFriendlyRecurrenceInfo(string seriesInfo) { RecurrenceInfo info = new RecurrenceInfo(); EndDateType endType = EndDateType.NotDefined; DateTime endDateValue = DateTime.MinValue; int noOccurrences; // Exit if not a Daily seriesInfo type if (!seriesInfo.StartsWith("D")) { return(null); } info.SetRecurrenceType(RecurrenceType.Daily); info.SetSeriesInfo(seriesInfo); // FORMATTING DEFINITIONS // Y = Yearly Designator // | 0 = Start Date (8 chars) // | | 1 = End Date (8 chars) // | | | 2 = Number of occurrences (4 chars) // | | | | 3 = Regeneration Type (1 char) // | | | | | 4 = End date type (1 char) // | | | | | | 5 = Regen Every x weeks // | | | | | | | // | | | | | | | // [0] [1-8] [9-16] [17-20] [21] [22] [23-25] // D 20071231 20171231 0000 1 1 000 string startDate = seriesInfo.Substring(1, 8); DateTime dtStartDate = new DateTime(int.Parse(startDate.Substring(0, 4)), int.Parse(startDate.Substring(4, 2)), int.Parse(startDate.Substring(6, 2))); string endDate = seriesInfo.Substring(9, 8); string occurrences = seriesInfo.Substring(17, 4); string dailyRegenType = seriesInfo.Substring(21, 1); string endDateType = seriesInfo.Substring(22, 1); int regenXDays = int.Parse(seriesInfo.Substring(23, 3)); endType = (EndDateType)(int.Parse(endDateType)); noOccurrences = int.Parse(occurrences); endType = (EndDateType)(int.Parse(endDateType)); noOccurrences = int.Parse(occurrences); // Get the EndDate before any modifications on it are performed if (endType == EndDateType.SpecificDate) { endDateValue = new DateTime(int.Parse(endDate.Substring(0, 4)), int.Parse(endDate.Substring(4, 2)), int.Parse(endDate.Substring(6, 2))); } info.SetEndDateType(endType); // Determine the Constructor by the type of End Date. // All constructors start with a Start date at a minimum. switch (endType) { case EndDateType.NumberOfOccurrences: info.SetStartDate(dtStartDate); info.SetNumberOfOccurrences(noOccurrences); break; case EndDateType.SpecificDate: info.SetStartDate(dtStartDate); info.SetEndDate(endDateValue); break; case EndDateType.NoEndDate: info.SetStartDate(dtStartDate); break; } info.SetDailyRegenType((DailyRegenType)(int.Parse(dailyRegenType))); // Determine the Type of dates to get, specific, custom, etc. switch (info.DailyRegenType) { case DailyRegenType.OnEveryXDays: info.SetDailyRegenEveryXDays(regenXDays); break; case DailyRegenType.OnEveryWeekday: // This is default. Nothing to set break; case DailyRegenType.NotSet: break; } return(info); }