diff --git a/EgwCoreLib.Utils/GestCalendario.cs b/EgwCoreLib.Utils/GestCalendario.cs new file mode 100644 index 0000000..9f93b88 --- /dev/null +++ b/EgwCoreLib.Utils/GestCalendario.cs @@ -0,0 +1,128 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EgwCoreLib.Utils +{ + /// + /// Utility gestione calendario + /// + public class GestCalendario + { + #region Public Methods + + /// + /// Calcolo data domenica di pasqua dell'YearReq indicato + /// + /// + /// + public static DateTime GetEasterSunday(int year) + { + int num = 0; + int num2 = 0; + int num3 = year % 19; + int num4 = year / 100; + int num5 = (num4 - num4 / 4 - (8 * num4 + 13) / 25 + 19 * num3 + 15) % 30; + int num6 = num5 - num5 / 28 * (1 - num5 / 28 * (29 / (num5 + 1)) * ((21 - num3) / 11)); + num = num6 - (year + year / 4 + num6 + 2 - num4 + num4 / 4) % 7 + 28; + num2 = 3; + if (num > 31) + { + num2++; + num -= 31; + } + + return new DateTime(year, num2, num); + } + + /// + /// Elenco festività (limitato ad ITALIA) + /// + /// + /// + /// + public static List ListHolidaysIta(int YearReq) + { + List list = new List(); + list.Add(new EventDetail + { + What = "Capodanno", + When = new DateTime(YearReq, 1, 1) + }); + list.Add(new EventDetail + { + What = "Epifania", + When = new DateTime(YearReq, 1, 6) + }); + list.Add(new EventDetail + { + What = "Lavoro", + When = new DateTime(YearReq, 5, 1) + }); + list.Add(new EventDetail + { + What = "Ferragosto", + When = new DateTime(YearReq, 8, 15) + }); + list.Add(new EventDetail + { + What = "Ognissanti", + When = new DateTime(YearReq, 11, 1) + }); + list.Add(new EventDetail + { + What = "Immacolata", + When = new DateTime(YearReq, 12, 8) + }); + list.Add(new EventDetail + { + What = "Natale", + When = new DateTime(YearReq, 12, 25) + }); + list.Add(new EventDetail + { + What = "S.Stefano", + When = new DateTime(YearReq, 12, 26) + }); + list.Add(new EventDetail + { + What = "Pasqua", + When = GetEasterSunday(YearReq) + }); + list.Add(new EventDetail + { + What = "Pasquetta", + When = GetEasterSunday(YearReq).AddDays(1.0) + }); + list.Add(new EventDetail + { + What = "Liberazione", + When = new DateTime(YearReq, 4, 25) + }); + list.Add(new EventDetail + { + What = "Repubblica", + When = new DateTime(YearReq, 6, 2) + }); + return list; + } + + #endregion Public Methods + + #region Public Classes + + public class EventDetail + { + #region Public Properties + + public string What { get; set; } = ""; + public DateTime When { get; set; } + + #endregion Public Properties + } + + #endregion Public Classes + } +} \ No newline at end of file