using System.Collections.Generic;
public static void Main()
var date = DateTime.Parse("12/25/2019");
Console.WriteLine(UKBankHoliday.IsBankHoliday(date));
public static class UKBankHoliday
#region Holiday Adjustments
private static DateTime FixWeekend(DateTime hol)
if (hol.DayOfWeek == DayOfWeek.Sunday)
else if (hol.DayOfWeek == DayOfWeek.Saturday)
private static DateTime FindFirstMonday(DateTime hol)
while (hol.DayOfWeek != DayOfWeek.Monday)
#region Individual Holidays
public static DateTime Christmas(int year)
DateTime hol = new DateTime(year, 12, 25);
public static DateTime BoxingDay(int year)
DateTime hol = new DateTime(year, 12, 26);
hol.DayOfWeek == DayOfWeek.Sunday ||
hol.DayOfWeek == DayOfWeek.Monday;
public static DateTime NewYear(int year)
DateTime hol = new DateTime(year, 1, 1);
public static DateTime? MayDay(int year)
if (year < 1978) return null;
return new DateTime(1995, 5, 8);
DateTime hol = new DateTime(year, 5, 1);
hol = FindFirstMonday(hol);
public static DateTime Spring(int year)
if (year == 2002) return new DateTime(2002, 6, 4);
if (year == 2012) return new DateTime(2012, 6, 4);
DateTime hol = new DateTime(year, 5, 24);
hol = FindFirstMonday(hol);
public static DateTime Summer(int year)
DateTime hol = new DateTime(year, 8, 25);
hol = FindFirstMonday(hol);
public static DateTime GoodFriday(int year)
DateTime hol = GetEaster(year);
public static DateTime EasterMonday(int year)
DateTime hol = GetEaster(year);
private static DateTime GoodFriday(DateTime easter)
DateTime hol = easter.AddDays(-2);
private static DateTime EasterMonday(DateTime easter)
DateTime hol = easter.AddDays(1);
public static IList<DateTime> BankHolidays(int year)
List<DateTime> bHols = new List<DateTime>();
bHols.Add(NewYear(year));
DateTime easter = GetEaster(year);
bHols.Add(GoodFriday(easter));
bHols.Add(EasterMonday(easter));
DateTime? dt = MayDay(year);
bHols.Add(new DateTime(2002, 6, 3));
bHols.Add(new DateTime(2012, 4, 29));
bHols.Add(new DateTime(2012, 6, 5));
bHols.Add(Christmas(year));
bHols.Add(BoxingDay(year));
public static IDictionary<DateTime, string> BankHolidayNames(int year)
var bHols = new Dictionary<DateTime, string>();
bHols.Add(NewYear(year), "New Year");
DateTime easter = GetEaster(year);
bHols.Add(GoodFriday(easter), "Good Friday");
bHols.Add(EasterMonday(easter), "Easter Monday");
bHols.Add(new DateTime(2011, 4, 29), "Royal Wedding");
DateTime? dt = MayDay(year);
bHols.Add(dt.Value, "Early May");
bHols.Add(Spring(year), "Spring");
bHols.Add(new DateTime(2002, 6, 3), "Golden Jubilee");
bHols.Add(new DateTime(2012, 6, 5), "Queen's Diamond Jubilee");
bHols.Add(Summer(year), "Summer");
bHols.Add(Christmas(year), "Christmas");
bHols.Add(BoxingDay(year), "Boxing Day");
public static DateTime NextWorkingDay(DateTime dt)
bool isWorkingDay = false;
while (isWorkingDay == false)
if (dt.DayOfWeek != DayOfWeek.Saturday &&
dt.DayOfWeek != DayOfWeek.Sunday &&
else if (dt.DayOfWeek == DayOfWeek.Saturday)
else if (dt.DayOfWeek == DayOfWeek.Sunday)
else if (dt.DayOfWeek == DayOfWeek.Friday)
public static bool IsBankHoliday(DateTime dt)
if ((year > 1973) && (NewYear(year) == dt))
if (dt.DayOfWeek != DayOfWeek.Monday &&
dt.DayOfWeek != DayOfWeek.Friday)
DateTime easter = GetEaster(year);
if (GoodFriday(easter) == dt)
if (EasterMonday(easter) == dt)
if (dt.DayOfWeek != DayOfWeek.Monday)
if (dt.DayOfWeek != DayOfWeek.Monday)
if (Christmas(year) == dt)
if (BoxingDay(year) == dt)
((dt.Day == 3) || (dt.Day == 4)))
private static DateTime GetEaster(int year)
int h = (c - c / 4 - (8 * c + 13) / 25 + 19 * g + 15) % 30;
int i = h - (h / 28) * (1 - (h / 28) * (29 / (h + 1)) * ((21 - g) / 11));
int j = (year + year / 4 + i + 2 - c + c / 4) % 7;
int easterDay = 1 + (p + 27 + (p + 6) / 40) % 31;
int easterMonth = 3 + (p + 26) / 30;
return new DateTime(year, easterMonth, easterDay);