From 341f2937dc77ab1db1ac1af35fce172d659eed98 Mon Sep 17 00:00:00 2001 From: Aisha Umar Gama Date: Sun, 27 Oct 2024 00:18:02 +0100 Subject: [PATCH] Update EN_NGHolidayStrategy.cs --- .../CultureStrategies/EN_NGHolidayStrategy.cs | 251 ++++++++---------- 1 file changed, 117 insertions(+), 134 deletions(-) diff --git a/src/DateTimeExtensions/WorkingDays/CultureStrategies/EN_NGHolidayStrategy.cs b/src/DateTimeExtensions/WorkingDays/CultureStrategies/EN_NGHolidayStrategy.cs index 620a3f8..d6d6384 100644 --- a/src/DateTimeExtensions/WorkingDays/CultureStrategies/EN_NGHolidayStrategy.cs +++ b/src/DateTimeExtensions/WorkingDays/CultureStrategies/EN_NGHolidayStrategy.cs @@ -1,18 +1,87 @@ using System; -using DateTimeExtensions.Common; -using DateTimeExtensions.WorkingDays; +using System.Collections.Generic; -namespace DateTimeExtensions.WorkingDays.CultureStrategies +namespace DateTimeExtensions.Common { + // Base class for holidays + public class Holiday + { + public string Name { get; } + public DateTime Date { get; } + + public Holiday(string name, DateTime date) + { + Name = name; + Date = date; + } + } + + // Class for fixed holidays + public class FixedHoliday : Holiday + { + public FixedHoliday(string name, int month, int day) + : base(name, new DateTime(DateTime.Now.Year, month, day)) + { + } + } + + // Class for relative holidays + public class RelativeHoliday : Holiday + { + public RelativeHoliday(string name, Holiday referenceHoliday, int offset) + : base(name, referenceHoliday.Date.AddDays(offset)) + { + } + } + + // Class for Islamic holidays + public class IslamicHoliday : Holiday + { + public IslamicHoliday(string name) : base(name, CalculateIslamicHolidayDate(name)) { } + + private static DateTime CalculateIslamicHolidayDate(string name) + { + // Placeholder for actual date calculation logic + return DateTime.Now; // Use appropriate logic to determine the date + } + } + + public static class GlobalHolidays + { + public static Holiday EasterSunday { get; } = new FixedHoliday("Easter Sunday", 4, 9); + public static Holiday NewYear { get; } = new FixedHoliday("New Year's Day", 1, 1); + } + + public abstract class HolidayStrategyBase + { + protected List InnerHolidays { get; } = new List(); + } + + public interface IHolidayStrategy + { + } + + [AttributeUsage(AttributeTargets.Class)] + public class LocaleAttribute : Attribute + { + public LocaleAttribute(string locale) { } + } +} + +namespace DateTimeExtensions.WorkingDays.CultureStrategies.NigerianHolidays +{ + using DateTimeExtensions.Common; + [Locale("en-NG")] public class EN_NGHolidayStrategy : HolidayStrategyBase, IHolidayStrategy { public EN_NGHolidayStrategy() { + // Adding holidays to the inner holidays list this.InnerHolidays.Add(GlobalHolidays.NewYear); - this.InnerHolidays.Add(GlobalHolidays.InternationalWorkersDay); this.InnerHolidays.Add(IndependenceDay); this.InnerHolidays.Add(DemocracyDay); + this.InnerHolidays.Add(WorkersDay); this.InnerHolidays.Add(ChristmasDay); this.InnerHolidays.Add(BoxingDay); this.InnerHolidays.Add(GoodFriday); @@ -22,148 +91,62 @@ public EN_NGHolidayStrategy() this.InnerHolidays.Add(EidAlAdha); } - // Fixed Holidays + private static readonly Holiday independenceDay = new FixedHoliday("Independence Day", 10, 1); + public static Holiday IndependenceDay => independenceDay; - // 1 October - Independence Day - private static Holiday independenceDay; - public static Holiday IndependenceDay - { - get - { - if (independenceDay == null) - { - independenceDay = new FixedHoliday("Independence Day", 10, 1); - } - return independenceDay; - } - } + private static readonly Holiday democracyDay = new FixedHoliday("Democracy Day", 6, 12); + public static Holiday DemocracyDay => democracyDay; - // 12 June - Democracy Day - private static Holiday democracyDay; - public static Holiday DemocracyDay - { - get - { - if (democracyDay == null) - { - democracyDay = new FixedHoliday("Democracy Day", 6, 12); - } - return democracyDay; - } - } + private static readonly Holiday workersDay = new FixedHoliday("Workers' Day", 5, 1); + public static Holiday WorkersDay => workersDay; - // 1 May - Workers' Day (also International Workers' Day) - private static Holiday workersDay; - public static Holiday WorkersDay - { - get - { - if (workersDay == null) - { - workersDay = new FixedHoliday("Workers' Day", 5, 1); - } - return workersDay; - } - } + private static readonly Holiday christmasDay = new FixedHoliday("Christmas Day", 12, 25); + public static Holiday ChristmasDay => christmasDay; - // 25 December - Christmas Day - private static Holiday christmasDay; - public static Holiday ChristmasDay - { - get - { - if (christmasDay == null) - { - christmasDay = new FixedHoliday("Christmas Day", 12, 25); - } - return christmasDay; - } - } + private static readonly Holiday boxingDay = new FixedHoliday("Boxing Day", 12, 26); + public static Holiday BoxingDay => boxingDay; - // 26 December - Boxing Day - private static Holiday boxingDay; - public static Holiday BoxingDay - { - get - { - if (boxingDay == null) - { - boxingDay = new FixedHoliday("Boxing Day", 12, 26); - } - return boxingDay; - } - } + private static readonly Holiday goodFriday = new RelativeHoliday("Good Friday", GlobalHolidays.EasterSunday, -2); + public static Holiday GoodFriday => goodFriday; - // Dynamic Holidays + private static readonly Holiday easterMonday = new RelativeHoliday("Easter Monday", GlobalHolidays.EasterSunday, 1); + public static Holiday EasterMonday => easterMonday; - // Good Friday (2 days before Easter Sunday) - private static Holiday goodFriday; - public static Holiday GoodFriday - { - get - { - if (goodFriday == null) - { - goodFriday = new RelativeHoliday("Good Friday", GlobalHolidays.EasterSunday, -2); - } - return goodFriday; - } - } + private static readonly Holiday eidAlFitr = new IslamicHoliday("Eid al-Fitr"); + public static Holiday EidAlFitr => eidAlFitr; - // Easter Monday (1 day after Easter Sunday) - private static Holiday easterMonday; - public static Holiday EasterMonday - { - get - { - if (easterMonday == null) - { - easterMonday = new RelativeHoliday("Easter Monday", GlobalHolidays.EasterSunday, 1); - } - return easterMonday; - } - } + private static readonly Holiday eidAlAdha = new IslamicHoliday("Eid al-Adha"); + public static Holiday EidAlAdha => eidAlAdha; - // Eid al-Fitr (Islamic calendar, date changes each year) - private static Holiday eidAlFitr; - public static Holiday EidAlFitr - { - get - { - if (eidAlFitr == null) - { - eidAlFitr = new IslamicHoliday("Eid al-Fitr"); - } - return eidAlFitr; - } - } + private static readonly Holiday maulid = new IslamicHoliday("Maulid an-Nabi"); + public static Holiday Maulid => maulid; + } +} - // Eid al-Adha (Islamic calendar, date changes each year) - private static Holiday eidAlAdha; - public static Holiday EidAlAdha - { - get - { - if (eidAlAdha == null) - { - eidAlAdha = new IslamicHoliday("Eid al-Adha"); - } - return eidAlAdha; - } - } +namespace HolidayProgram +{ + using DateTimeExtensions.Common; + using DateTimeExtensions.WorkingDays.CultureStrategies.NigerianHolidays; - // Maulid an-Nabi (Birth of Prophet Muhammad) - private static Holiday maulid; - public static Holiday Maulid + public class Program + { + public static void Main(string[] args) { - get - { - if (maulid == null) - { - maulid = new IslamicHoliday("Maulid an-Nabi"); - } - return maulid; - } + var holidayStrategy = new EN_NGHolidayStrategy(); + + Console.WriteLine("Nigerian Holidays:"); + Console.WriteLine($"1. {EN_NGHolidayStrategy.IndependenceDay.Name} - {EN_NGHolidayStrategy.IndependenceDay.Date.ToShortDateString()}"); + Console.WriteLine($"2. {EN_NGHolidayStrategy.DemocracyDay.Name} - {EN_NGHolidayStrategy.DemocracyDay.Date.ToShortDateString()}"); + Console.WriteLine($"3. {EN_NGHolidayStrategy.WorkersDay.Name} - {EN_NGHolidayStrategy.WorkersDay.Date.ToShortDateString()}"); + Console.WriteLine($"4. {EN_NGHolidayStrategy.ChristmasDay.Name} - {EN_NGHolidayStrategy.ChristmasDay.Date.ToShortDateString()}"); + Console.WriteLine($"5. {EN_NGHolidayStrategy.BoxingDay.Name} - {EN_NGHolidayStrategy.BoxingDay.Date.ToShortDateString()}"); + Console.WriteLine($"6. {EN_NGHolidayStrategy.GoodFriday.Name} - {EN_NGHolidayStrategy.GoodFriday.Date.ToShortDateString()}"); + Console.WriteLine($"7. {EN_NGHolidayStrategy.EasterMonday.Name} - {EN_NGHolidayStrategy.EasterMonday.Date.ToShortDateString()}"); + Console.WriteLine($"8. {EN_NGHolidayStrategy.EidAlFitr.Name} - {EN_NGHolidayStrategy.EidAlFitr.Date.ToShortDateString()}"); + Console.WriteLine($"9. {EN_NGHolidayStrategy.EidAlAdha.Name} - {EN_NGHolidayStrategy.EidAlAdha.Date.ToShortDateString()}"); + Console.WriteLine($"10. {EN_NGHolidayStrategy.Maulid.Name} - {EN_NGHolidayStrategy.Maulid.Date.ToShortDateString()}"); + + Console.ReadLine(); } } }