public Array getDatesFromWeekInput_ISO()
{
int year = jahreingeben;
int anzKW = System.Globalization.CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(new DateTime(year, 12, 31), System.Globalization.CalendarWeekRule.FirstFourDayWeek, System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek);
DateTime startdate = new DateTime(year, 1, 1);
DateTime[,] weeksanddates = new DateTime[anzKW, 7];
for (int i = -1; i < anzKW; i++)
{
for (int j = 0; j < 7; j++)
{
DateTime tempdate = startdate;
if (i == -1)
{
if (tempdate.DayOfWeek == DayOfWeek.Monday)
{
weeksanddates[i + 1, 0] = tempdate;
weeksanddates[i + 1, 1] = new DateTime(year, 1, 2);
weeksanddates[i + 1, 2] = new DateTime(year, 1, 3);
weeksanddates[i + 1, 3] = new DateTime(year, 1, 4);
weeksanddates[i + 1, 4] = new DateTime(year, 1, 5);
weeksanddates[i + 1, 5] = new DateTime(year, 1, 6);
weeksanddates[i + 1, 6] = new DateTime(year, 1, 7);
startdate = tempdate.AddDays(6);
j = 7; i = 0;
}
else if (tempdate.DayOfWeek == DayOfWeek.Tuesday)
{
weeksanddates[i + 1, 0] = new DateTime((year - 1), 12, 31);
weeksanddates[i + 1, 1] = tempdate;
weeksanddates[i + 1, 2] = new DateTime(year, 1, 2);
weeksanddates[i + 1, 3] = new DateTime(year, 1, 3);
weeksanddates[i + 1, 4] = new DateTime(year, 1, 4);
weeksanddates[i + 1, 5] = new DateTime(year, 1, 5);
weeksanddates[i + 1, 6] = new DateTime(year, 1, 6);
startdate = tempdate.AddDays(5);
j = 7; i = 0;
}
else if (tempdate.DayOfWeek == DayOfWeek.Wednesday)
{
weeksanddates[i + 1, 0] = new DateTime((year - 1), 12, 30);
weeksanddates[i + 1, 1] = new DateTime((year - 1), 12, 31);
weeksanddates[i + 1, 2] = tempdate;
weeksanddates[i + 1, 3] = new DateTime(year, 1, 2);
weeksanddates[i + 1, 4] = new DateTime(year, 1, 3);
weeksanddates[i + 1, 5] = new DateTime(year, 1, 4);
weeksanddates[i + 1, 6] = new DateTime(year, 1, 5);
startdate = tempdate.AddDays(4);
j = 7; i = 0;
}
else if (tempdate.DayOfWeek == DayOfWeek.Thursday)
{
weeksanddates[i + 1, 0] = new DateTime((year - 1), 12, 29);
weeksanddates[i + 1, 1] = new DateTime((year - 1), 12, 30);
weeksanddates[i + 1, 2] = new DateTime((year - 1), 12, 31);
weeksanddates[i + 1, 3] = tempdate;
weeksanddates[i + 1, 4] = new DateTime(year, 1, 2);
weeksanddates[i + 1, 5] = new DateTime(year, 1, 3);
weeksanddates[i + 1, 6] = new DateTime(year, 1, 4);
startdate = tempdate.AddDays(3);
j = 7; i = 0;
}
//weniger als 4 Tage der Woche liegen im neuen Jahr
else if (tempdate.DayOfWeek == DayOfWeek.Friday)
{
j = 7; i = -1;
tempdate = tempdate.AddDays(3);
}
else if (tempdate.DayOfWeek == DayOfWeek.Saturday)
{
//j=0 + i=1 + adddays(3)
j = 7; i = -1;
tempdate = tempdate.AddDays(2);
}
else if (tempdate.DayOfWeek == DayOfWeek.Sunday)
{
j = 7; i = -1;
tempdate = tempdate.AddDays(1);
}
}
else
{
weeksanddates[i, j] = tempdate;
}
if (tempdate.Day == 31 && tempdate.Month == 12)
{
//2008 --> 31. = mi
//2009 --> 31. = do
if (tempdate.DayOfWeek == DayOfWeek.Monday)
{
//Mo aus Array löschen
weeksanddates[i, 0] = new DateTime(1, 1, 1);
}
else if (tempdate.DayOfWeek == DayOfWeek.Tuesday)
{
//Mo,Di aus Array löschen
weeksanddates[i, 0] = new DateTime(1, 1, 1);
weeksanddates[i, 1] = new DateTime(1, 1, 1);
}
else if (tempdate.DayOfWeek == DayOfWeek.Wednesday)
{
//Mo,Di,Mi aus Array löschen
weeksanddates[i, 0] = new DateTime(1, 1, 1);
weeksanddates[i, 1] = new DateTime(1, 1, 1);
weeksanddates[i, 2] = new DateTime(1, 1, 1);
}
else if (tempdate.DayOfWeek == DayOfWeek.Thursday)
{
//Fr,Sa,So zu array hinzufügen
weeksanddates[i, 4] = tempdate.AddDays(1);
weeksanddates[i, 5] = tempdate.AddDays(2);
weeksanddates[i, 6] = tempdate.AddDays(3);
}
else if (tempdate.DayOfWeek == DayOfWeek.Friday)
{
//Sa,So zu array hinzufügen
weeksanddates[i, 5] = tempdate.AddDays(1);
weeksanddates[i, 6] = tempdate.AddDays(2);
}
else if (tempdate.DayOfWeek == DayOfWeek.Saturday)
{
//So zu array hinzufügen
weeksanddates[i, 5] = tempdate.AddDays(1);
}
else if (tempdate.DayOfWeek == DayOfWeek.Sunday)
{
//Keine Aktion, Sonntag ist letzter Tag im Jahr
}
break; //Abbruch der kompletten Schleife
}
tempdate = startdate.AddDays(1);
startdate = tempdate;
}
}
return weeksanddates;
}