softaware.Holidays - How Carl Friedrich Gauß helps us in resource planning and image categorization.

softaware.Holidays - How Carl Friedrich Gauß helps us in resource planning and image categorization.

Holidays are those days in the year most of us are looking forward to, probably except you are the one who has to invite your family. ;)
Why we have to take care of them at softaware, why we created softaware.Holidays and how Carl Friedrich Gauß helped us realizing this library will be discussed in the following article.

TL;DR

Take a look at the repo: softaware\library-holidays.

Introduction

You wouldn’t believe, but the origins of this article date back to the years 325 and 525 when the First Council of Nicaea and Pope John I decided the the Easter Sunday takes place on the first Sunday after full the moon next after the vernal equinox.
This information is in fact useful because based on the date of the Easter Sunday all other holidays (at least in Austria) can be calculated fairly easily thanks to Carl Friedrich Gauß.

In 1800 he realeased the first version of his formula to calculate the Easter Sunday. 1816 he corrected one of the variables and Hermann Kinkelin extended it so that the requirement that the latest possible date for the Easter Sunday is the 25th of April in the 19th century gets respected as well.
Thanks to those mathematicians the code to calculate the Easter Sunday was written pretty fast and I could focus more on library design.

Motivation

But why do we even need to calculate the holidays?
Some of the products we develop need to be aware of holidays, e.g.

  1. the red cross distributes house medical care where the doctor’s shifts on holidays are different, or
  2. when planning resources for employees it makes a difference if a week has 4 or 5 workdays, or
  3. knowing the dates of holidays helps us detecting the occasion of an image series when creating photo books.

To minimize mistakes and increase our productivity we recently created softaware.Holidays, a library that is capable of creating these holidays. (at least for Austria right now)
The main focus while developing the library was to ease the usage, ensure good readability and be extensible via composition.

Usage

As a result the library can be included via NuGet (select your desired country) and can then be used like:

var holidays = new Holidays.Generator().ForAustria(2018);

That’s it, you know have the Austrian holidays for the year 2018 stored in holidays.

Contributing

Apart from the easy usage it was important that the library can be extended easily and readable.
The following example shows all you need to know.
Simply create an extension method for the Generator class in which you can use the holiday generation functions WithDate(...), BeforeEaster(...) and AfterEaster(...) after you initialized a helper factory with generator.Create(/* year */).
It would also be awesome if you create a Test project as shown in the repository. 😎

public static class Generator
{
    public static IEnumerable<Holiday> For/* Country */(this Holidays.Generator generator, int year)
    {
        var holiday = generator.Create(year);
        yield return holiday.WithDate(/* name of holiday */, month: /* month */, day: /* day */);
        yield return holiday.BeforeEaster(/* name of holiday */, days: /* days */);
        yield return holiday.AfterEaster(/* name of holiday */, days: /* days */);
    }
}

For a complete example please visit: softaware.Holidays.Austria/Generator.cs
.

We would really love it if somebody likes the idea and the concept of an extensible holiday generation library and sends us a Pull-Request.
Of course we would also be delighted if somebody uses softaware.Holidays.Core and builds upon this base for creating generators for other countries.
Just keep in mind that contributions are always welcome and we won’t hesitate to merge your PR into the repository.

GitHub, NuGet

Happy Coding! 👏