Files
BeWoPlaner/Service/Plugins/VacationService.cs
2017-06-11 16:01:01 +02:00

101 lines
3.4 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using BeWo.Data.Access;
using BeWo.Data.Entities;
using BeWo.Service.DCEntityMapper;
using BS.Shared;
using BS.Shared.Core;
using BS.Shared.DataContracts.Compact;
using BS.Shared.Extensions;
namespace BeWo.Service.Plugins
{
public class VacationService : AbstractIDSpecificDefaultClass<VacationService>
{
public virtual bool IstFeiertag(DateTime start)
{
List<DateTime> feiertage = GetFeiertage(start.Year);
foreach (var ft in feiertage)
{
if (start.Date == ft)
return true;
}
return false;
}
public virtual List<DateTime> GetFeiertage(int year)
{
List<DateTime> list = new List<DateTime>();
list.Add(new DateTime(year, 1, 1)); // "Neujahr"));
//list.Add(new DateTime(year, 1, 6)); // , "Heilige Drei Könige"));
list.Add(new DateTime(year, 5, 1)); // , "Tag der Arbeit"));
//list.Add(new DateTime(year, 8, 15)); // , "Mariä Himmelfahrt"));
list.Add(new DateTime(year, 10, 3)); // , "Tag der dt. Einheit"));
//list.Add(new DateTime(year, 10, 31)); // , "Reformationstag"));
list.Add(new DateTime(year, 11, 1)); // , "Allerheiligen "));
list.Add(new DateTime(year, 12, 24)); // , "Heilig Abend"));
list.Add(new DateTime(year, 12, 25)); // , "1. Weihnachtstag"));
list.Add(new DateTime(year, 12, 26)); // , "2. Weihnachtstag"));
if (year == 2017)
{
list.Add(new DateTime(year, 10, 31)); // , "Reformationstag"));
}
DateTime osterSonntag = GetOsterSonntag(year);
//list.Add(osterSonntag); // , "Ostersonntag"));
//list.Add(osterSonntag.AddDays(-3)); // , "Gründonnerstag")); q
//list.Add(osterSonntag.AddDays(-48)); // , "Rosenmontag"));
list.Add(osterSonntag.AddDays(-2)); // , "Karfreitag"));
list.Add(osterSonntag.AddDays(1)); // , "Ostermontag"));
list.Add(osterSonntag.AddDays(39)); // , "Christi Himmelfahrt"));
//list.Add(osterSonntag.AddDays(49)); // , "Pfingstsonntag"));
list.Add(osterSonntag.AddDays(50)); // , "Pfingstmontag"));
list.Add(osterSonntag.AddDays(60)); // , "Fronleichnam"));
//01.01. Neujahr
//01.05. Tag der Arbeit
//03.10. Tag der Deutschen Einheit
//01.11. Allerheiligen
//25.12. 1. Weihnachtstag
//26.12. 2. Weihnachtstag
//Karfreitag
//Ostermontag
//Christi Himmelfahrt (39 Tage nach Ostersonntag)
//Pfingstmontag (50 Tage nach Ostersonntag)
//Fronleichnam (60 Tage nach Ostersonntag)
//24.12. Heilig Abend
return list;
}
public static DateTime GetOsterSonntag(int year)
{
int g, h, c, j, l, i;
g = year%19;
c = year/100;
h = ((c - (c/4)) - (((8*c) + 13)/25) + (19*g) + 15)%30;
i = h - (h/28)*(1 - (29/(h + 1))*((21 - g)/11));
j = (year + (year/4) + i + 2 - c + (c/4))%7;
l = i - j;
int month = (int) (3 + ((l + 40)/44));
int day = (int) (l + 28 - 31*(month/4));
return new DateTime(year, month, day);
}
}
}