Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Few new methods #100

Open
IeuanWalker opened this issue Jun 7, 2023 · 1 comment
Open

Few new methods #100

IeuanWalker opened this issue Jun 7, 2023 · 1 comment

Comments

@IeuanWalker
Copy link

Think these extensions would be useful.

The reverse of the current booleans -

  • IsNotPublicHoliday
  • IsNotBankHoliday
  • IsNotWorkingDay

Get an individual holiday.
Currently there is GetHolidaysInDateRange, i have a use case where im checking an individual date at a time, then add the holiday name to the record if there is a holiday.

Let me know what you think of the above, and if all good i'll look at doing a PR

@martinjw
Copy link
Owner

I think the booleans are easily handled with ! /not in front of the original - also simple negations will simply inflate the number of methods and reduce discoverability.

For your get holiday name, something like this?

            var result = new USAPublicHoliday().GetHolidayForDate(new DateTime(2023, 7, 4));
            Assert.IsNotNull(result);
            var name = result.GetName();
            Assert.AreEqual("Independence Day", name);

Implementation is

        public Holiday GetHolidayForDate(DateTime dt)
        {
            var holidays = PublicHolidaysInformation(dt.Year);
            return holidays.FirstOrDefault(h => h.ObservedDate.Date == dt.Date);
        }

Would be nice to mark the nullable ref type, but it won't work well with .net framework targets

martinjw added a commit that referenced this issue Jul 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants