Monday, July 30, 2012

Recycle calendars

Many years share their structure in such a way as to be able to use the same calendar.
For example in 2012 you can use a calendar or diary designed for 1984. Here is a short script to find out which years this is valid for.


Dictionary<string,List<int>> similarYears = new Dictionary<string,List<int>>();
for(int year = DateTime.MinValue.Year; year <= DateTime.MaxValue.Year; year++)
{
DateTime Jan1 = new DateTime(year, 1, 1);
DateTime Dec31 = new DateTime(year, 12, 31);
string key = Jan1.DayOfWeek.ToString() + ":" + Dec31.DayOfWeek.ToString();
if (!similarYears.ContainsKey(key))
similarYears[key] = new List<int>();
similarYears[key].Add(year);
}

No comments: