// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Collections; namespace E { public class MainClass { public static ArrayList FindInterval(ArrayList total, DateTime start, DateTime end) { ArrayList res = new ArrayList(); foreach(DateTime dt in total) { if(start <= dt && dt <= end) { res.Add(dt); } } return res; } public static ArrayList[] FindGroups(ArrayList total, DateTime start, int ndays) { int span = (int)(((DateTime)total[total.Count-1])-start).TotalDays+1; ArrayList[] res = new ArrayList[(span-1)/ndays+1]; for(int i = 0; i < res.Length; i++) { res[i] = FindInterval(total, start.AddDays(i*ndays), start.AddDays(i*ndays+ndays-1)); } return res; } public static void Main(string[] args) { ArrayList lst = new ArrayList(); lst.Add(DateTime.Parse("15-06-2006")); lst.Add(DateTime.Parse("16-06-2006")); lst.Add(DateTime.Parse("17-06-2006")); lst.Add(DateTime.Parse("18-06-2006")); lst.Add(DateTime.Parse("21-06-2006")); lst.Add(DateTime.Parse("22-06-2006")); lst.Add(DateTime.Parse("23-06-2006")); lst.Add(DateTime.Parse("25-06-2006")); lst.Add(DateTime.Parse("27-06-2006")); ArrayList[] groups = FindGroups(lst, DateTime.Parse("15-06-2006"), 3); foreach(ArrayList g in groups) { foreach(DateTime dt in g) { Console.Write(" " + dt); } Console.WriteLine(); } } } }