How to

This is a short guide on how to use the holidays assembly.

Date extensions

Out of the box, the assembly will use embedded Xml resources using the thread's Culture (CultureInfo) to calculate which dates are holidays.

using Holidays;

DateTime now = DateTime.Now;
// Some regular DateTime extensions:
DateTime firstMonday = now.FirstInMonth(DayOfWeek.Monday);
DateTime lastMonday = now.LastInMonth(DayOfWeek.Monday);
// Some holiday DateTime extensions
if (now.IsHoliday()) { /* Today is a holiday! */ }
if (now.IsWeekend()) { /* Today it's weekend! */ }

Custom Holiday Data

If the needed culture is not included in the assembly, or you for some reason need to use a different set of data, you can use another method to calculate the holidays.

using Holidays;
using Holidays.CountryCalculators;

DateTime now = DateTime.Now;
BaseCalculator calcUK = CalculatorFactory.GetCalculator("en-UK");
if (calc.UK(now, customXML)) { /* Today is a holiday! */ }

Dynamic date calculators

At the moment the assembly supports Easter calculation using two different algoritms, the Gauss algoritm and the Meeus-Jones-Butcher algoritm.

We have fully implemented support for Danish holidays, and are working on British and German. Please feel free to contact us and help with support for your country's holidays.

With help, we will expand this.

Xml format

<?xml version="1.0" encoding="utf-8" ?>
<Dates>
	<Date Type="static" Month="12" Day="31" Holiday="true">
		<Name><![CDATA[Nytårsaftensdag]]></Name>
	</Date>
	<Date Type="dynamic" Base="EasterGauss" Holiday="true" DeltaDay="50">
		<Name><![CDATA[2. Pinsedag]]></Name>
	</Date>
</Dates>

The example includes a static holiday (same day and month each year), and a dynamic holiday. The dynamic holidays are calculated as a set number of days (negative, positive or 0) from a base date. In this case the base date is Easter, using the Gauss calculation. Supported Base values right now are EasterGauss and EasterMeeusJonesButcher.

<Dates>
	<Date Type="static" Month="4" Day="1" Holiday="true" StartYear="1889" EndYear="1941">
		<Name><![CDATA[วันขึ้นปีใหม่]]></Name>
	</Date>
</Dates>

This example demonstrates how we calculate old and new holidays by adding a StartYear and/or EndYear.

Last edited Jan 11, 2013 at 6:54 AM by steentottrup, version 2

Comments

No comments yet.