joaomatossilva / DateTimeExtensions

This project is a merge of several common DateTime operations on the form of extensions to System.DateTime, including natural date difference text (precise and human rounded), holidays and working days calculations on several culture locales.

Home Page:http://datetimeextensions.azurewebsites.net/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Indigenous People's/Columbus Day

BakeryD opened this issue · comments

commented

In my company's payment scheduling system, we only take payments on non-holiday weekdays and the second monday in October is not considered a business holiday. Is there any way to use the default holiday strategy for your locale +/- desired holidays?

ie in Startup.cs for .NET Core:

        ...
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddHolidays(new CustomHoliday());
            DateTimeExtensions.IgnoreHolidays(....);
            ...
        }
commented

Current workaround is to hard code a check for your locale and the desired Holiday then ignore it which is... not pretty

       public bool IsBusinessDay(DateTime desiredDate)
       {
            // HACK
            // Columbus day is a bank holiday, but not a business holiday
            // see https://github.com/joaomatossilva/DateTimeExtensions/issues/100
            var year = desiredDate.Year;
            var columbusDay = DateTimeExtensions.WorkingDays.CultureStrategies
                .EN_USHolidayStrategy.ColumbusDay.GetInstance(year);
            return WorkingDaysExtensions.IsWorkingDay(desiredDate) || columbusDay.GetValueOrDefault() == desiredDate
        }

Hi
I think you should be able to create your own strategy and add your own holiday instances.
Let me try to get you an example as soon I find the time.

But while I try to give out an example (and this is already an indication that Extensibility is a bit too hard, so this is a design issue I need to tackle) If I understood, ColumbusDay is not actually a National Holiday?

Here: https://github.com/joaomatossilva/DateTimeExtensions/blob/master/tests/DateTimeExtensions.Tests/Extensibility/CustomCultureInfoTests.cs

It's an example of how you can provide your own WorkingDayCultureInfo. In this example, the code is inheriting directly from the en-US locale, as per your example.

Hi,
I have the same issue and I was able to create my own HolidayStrategy following your test, nevertheless, I can't seem to find (or figure out) the way (if possible) to set my custom strategy as a global configuration so all the code that I already have use my new custom holiday strategy.

Can you point me in the right direction?

Looking before, you are using Asp.Net Core..
You can register your custom WorkingDayCultureInfo, as IWorkingDatCultureInfo, and request that instance on your dependencies.
Then all you need is to use the overloads where you specify the IWorkingDatCultureInfo instance.

Thank you for your response. We can do that, nevertheless, when you are working on a team is very easily that a developer forget to use the overloaded method which can introduce bugs hard to find.

I guess a good unit test code coverage could find those bugs, but, don't you think the library will be a lot more flexible if we can somehow define a custom strategy in in a global way like StartUp so instead of using the culture name by default, it will use the defined strategy?

In my humble opinion creating custom strategies is already super easy to do, and that's very powerful, the opportunity area is in how you use/set that custom strategy.

Just something to think about.

For now what I think I will do is create a specific project in my solution redefining the extension methods that we would use so we specify the custom strategy in one place, so the rest of the projects will reference this one instead of the Extensions, in other words, encapsulate DateTimeExtensions.

commented

Closing issue since this issue has been resolved for me. @ayepiz I think that's a great idea and opened #101