public static List <string> ConcatDays(string[] dates) { var leavesInterval = new List <string>(); var tempDate = GetDate(dates[0]).AddDays(-1); var lastDate = GetDate(dates[0]); DateTime currentDate = DateTime.MinValue; DateTime nextDay; DateTime lastCurrentDate = DateTime.MinValue; foreach (string date in dates) { currentDate = GetDate(date); tempDate = ForwardNonWorkingDays(tempDate); nextDay = tempDate.AddDays(1); if (nextDay.Date == currentDate.Date || HollidaysManager.IsHolidayDay(nextDay)) { tempDate = currentDate; } else { tempDate = HollidaysManager.IsHolidayDay(tempDate) ? BackwardNonWorkingDays(tempDate) : tempDate; lastCurrentDate = tempDate; leavesInterval.Add(FormatDateInterval(lastDate, tempDate)); lastDate = tempDate = currentDate; } } if (currentDate.Date != lastCurrentDate.Date) { leavesInterval.Add(FormatDateInterval(lastDate, tempDate)); } return(leavesInterval); }
private static DateTime BackwardNonWorkingDays(DateTime from) { var yesturday = from.AddDays(-1); return((HollidaysManager.IsHolidayDay(yesturday)) ? BackwardNonWorkingDays(yesturday) : yesturday); }
private static DateTime ForwardNonWorkingDays(DateTime from) { var nextDay = from.AddDays(1); return((HollidaysManager.IsHolidayDay(nextDay)) ? ForwardNonWorkingDays(nextDay) : from); }