Files
SteamWare/SteamWareLib/calendarMan.cs
T
2020-02-03 14:00:20 +01:00

85 lines
2.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SteamWare
{
/// <summary>
/// Singolo dettaglio evento
/// </summary>
public class EventDetail
{
/// <summary>
/// Data di riferimento
/// </summary>
public DateTime when { get; set; }
/// <summary>
/// Nome evento
/// </summary>
public string what { get; set; } = "";
}
/// <summary>
/// Classe gestione procedure Calendario (es festività)
/// </summary>
public class calendarMan
{
/// <summary>
/// Calculate Easter Sunday for any given year.
/// src.: https://stackoverflow.com/a/2510411/1233379
/// </summary>
/// <param name="year">The year to calcolate Easter against.</param>
/// <returns>a DateTime object containing the Easter month and day for the given year</returns>
public static DateTime GetEasterSunday(int year)
{
int day = 0;
int month = 0;
int g = year % 19;
int c = year / 100;
int h = (c - (int)(c / 4) - (int)((8 * c + 13) / 25) + 19 * g + 15) % 30;
int i = h - (int)(h / 28) * (1 - (int)(h / 28) * (int)(29 / (h + 1)) * (int)((21 - g) / 11));
day = i - ((year + (int)(year / 4) + i + 2 - c + (int)(c / 4)) % 7) + 28;
month = 3;
if (day > 31)
{
month++;
day -= 31;
}
return new DateTime(year, month, day);
}
/// <summary>
/// Elenco festività per l'anno indicato
/// </summary>
/// <param name="anno"></param>
/// <returns></returns>
public static List<EventDetail> elencoFestAnno(int anno)
{
List<EventDetail> answ = new List<EventDetail>();
// aggiungo le feste comandate...
answ.Add(new EventDetail() { what = "Capodanno", when = new DateTime(anno, 1, 1) });
answ.Add(new EventDetail() { what = "Epifania", when = new DateTime(anno, 1, 6) });
answ.Add(new EventDetail() { what = "Lavoro", when = new DateTime(anno, 5, 1) });
answ.Add(new EventDetail() { what = "Ferragosto", when = new DateTime(anno, 8, 15) });
answ.Add(new EventDetail() { what = "Ognissanti", when = new DateTime(anno, 11, 1) });
answ.Add(new EventDetail() { what = "Immacolata", when = new DateTime(anno, 12, 8) });
answ.Add(new EventDetail() { what = "Natale", when = new DateTime(anno, 12, 25) });
answ.Add(new EventDetail() { what = "S.Stefano", when = new DateTime(anno, 12, 26) });
// Pasqua + Pasquetta
answ.Add(new EventDetail() { what = "Pasqua", when = GetEasterSunday(anno) });
answ.Add(new EventDetail() { what = "Pasquetta", when = GetEasterSunday(anno).AddDays(1) });
// feste ITA
answ.Add(new EventDetail() { what = "Liberazione", when = new DateTime(anno, 4, 25) });
answ.Add(new EventDetail() { what = "Repubblica", when = new DateTime(anno, 6, 2) });
return answ;
}
}
}