
New Year holidays are coming ... and it's time to talk about holidays. When developing an application with the support of holiday dates, a number of questions arise: how can such data be obtained and from where, how to use and process it?
In this article I want to talk about the resources associated with the holidays, and to share personal experience of their use in popular services and programs. I will consider options for working with these services using the example of our
XtraScheduler scheduler . And at the end of the article I will give some statistics on holidays for different countries of the world.
Online resources
There are information and reference resources with a variety of calendars - solar, lunar, calendars with various types of holidays, schedules of sporting events, etc.
')
In Runet, one such resource is the
Calendar of Events (
http://www.calend.ru/ ), where you can find information about state, professional, religious, and other holidays, divided into categories. All of them are presented in the form of ics-files of
iCalendar format, which can be used in your applications.

As other examples, I’ll give you the resources that
Yandex Calendar presents :
Apple.com ,
Mozilla.org ,
iCalShare.com . They also contain collections of publicly available ics files.
Our XtraScheduler scheduler can import data from the iCalendar format, so you can use any of the resources listed above. To do this, we use the
iCalendarImporter class from the separate assembly
DevExpress.XtraScheduler.v10.2.iCalendarExchange.dll . It implements all the necessary functionality of loading from the ics-file and creating calendar objects.
Preset Holidays
In addition to the resources offered, the
Yandex Calendar also contains predefined holiday dates. On the date navigator and in various views, they are marked in red and have a hint with a description. I am glad that there are postponements of working days - even though the color of the date in the navigator does not always correspond to the color of the date in the calendar itself.

Since XtraScheduler is a component, it’s not necessary to store the preset date set in it. This is due to the fact that the situation with the holidays varies from year to year and the requirements imposed by users may differ depending on the country or usage scenario. Therefore, instead of introducing a fixed set of holidays, we provided the user with a collection property for this set of dates and made it possible to determine the list of working days, holidays, and “working” weekends.
public WorkDaysCollection WorkDays { get {... } }
Below is the next set of element classes in this collection, which “overlaps” all options for using weekends.
public abstract class WorkDay : ICloneable { public abstract bool IsWorkDay(DateTime date); } public class WeekDaysWorkDay : WorkDay { public WeekDays WeekDays {get { ...} } } public abstract class KnownDateDay : WorkDay { public string DisplayName { get { ... } set { ... } } public DateTime Date { get { ... } } } public class Holiday : KnownDateDay { public string Location { get { ...} set { ... } } } public class ExactWorkDay : KnownDateDay { }
Holidays as calendar events
This option implies that an event in the calendar is directly created for each holiday.
Let's return to the
Yandex calendar . On first consideration, I did not find how to add holidays to the calendar, although I expected to see the mention of holidays somewhere near the Playbill and the TV program. But I found a universal way to add any events (including holidays), using import from the ics-file. The resulting list can be imported either in a new or in an existing calendar.
I tried to import the list of “International holidays” (
http://www.calend.ru/img/export/ical-wholeworld.ics ) from the resource described above.
Unfortunately, Yandex could not manage to import the selected calendar (although, to put it mildly, the format of the proposed file is not perfect). But the import from the resources proposed by Yandex itself works perfectly.
In the
Google Calendar, the situation is somewhat different. Along with importing calendars from a file, importing via the link indicated, importing from another account, there is one more option.

We immediately see the “Other calendars” list and open the “View interesting calendars” menu item (by the way, the menu name is interesting) we will get into a whole collection of various calendar events, including sports, moon phases, etc. One of them is a list of pre-installed holidays - approximately 30 countries.

Just select the one you need and click “subscribe” - and the list of calendar events will be added as a separate calendar. The event for the day will be added and, as a result, the corresponding date will appear in bold on the date navigator.
By the way, Google successfully coped with the task of importing our International Holidays file.
XtraScheduler when importing holidays from the ics-file also creates separate events for the whole day. How can I use it? It is enough to enable the option that prohibits having time-overlapping events:
schedulerControl1.OptionsCustomization.AllowAppointmentConflicts = AppointmentConflictsMode.Forbidden;
and on this holiday it will be impossible to create any other event.
Holidays in desktop applications
In addition to ics-files, there is another way to get a list of official public holidays by country.
One of the sources, if you have installed
Microsoft Office , is the
outlook.hol file, which is located in the subfolders of the installed product, for example, here:
C: \ Program Files \ Microsoft Office \ Office12 \ 1049 \ outlook.hol "
The data in this file is divided into sections-countries and contains a fixed list of strings representing holidays for several years ago and forward.
... [] 84 ,2006/1/1 ,2007/1/1 ,2008/1/1 ,2009/1/1 ,2010/1/1 ,2011/1/1 ,2012/1/1 ...
In the version of office 2010, data on holidays is presented from 2009 to 2028
This data is used in the Outlook Calendar. In the calendar settings, you can add holidays for the specified country. Holidays will also be added as physical calendar events.

Let us consider how the holiday string is defined in this file. The line storing information about the holiday consists of its name, date and calendar identifier. Note that for a number of countries where dates are represented not only in the Gregorian calendar, it is necessary to perform date conversions.
... [] 42 ... ,1424/3/12,6 ...
Such date conversions are easy to do with built-in tools if you use .NET.
When implementing the functional holidays in XtraScheduler in order to make life easier for users, we have provided the ability to download this file, although we ourselves do not use it. We have created a separate class that loads this data and does the necessary operations with dates. At the same time, all the necessary date conversions between different calendars will be performed by us and do not require writing additional code.
The number of supported calendars for conversions can be seen from the code below.
public class OutlookHolidaysLoader { #region CalendarTypes consts internal const int CAL_GREGORIAN = 1; internal const int CAL_GREGORIAN_ARABIC = 10; internal const int CAL_GREGORIAN_ME_FRENCH = 9; internal const int CAL_GREGORIAN_US = 2; internal const int CAL_GREGORIAN_XLIT_ENGLISH = 11; internal const int CAL_GREGORIAN_XLIT_FRENCH = 12; internal const int CAL_HEBREW = 8; internal const int CAL_HIJRI = 6; internal const int CAL_JAPAN = 3; internal const int CAL_JULIAN = 13; internal const int CAL_KOREA = 5; internal const int CAL_TAIWAN = 4; internal const int CAL_THAI = 7; #endregion internal const int DefaultCalendarType = CAL_GREGORIAN; public string[] ExtractLocations(string fileName) { } public string[] ExtractLocations(Stream stream) { } public HolidayBaseCollection FromFile(string fileName) { } public HolidayBaseCollection FromFile(string fileName, string[] locations) { } public HolidayBaseCollection FromFile(string fileName, Encoding encoding, string[] locations) { } public HolidayBaseCollection FromStream(Stream stream) { } public HolidayBaseCollection FromStream(Stream stream, string[] locations) { } public HolidayBaseCollection FromStream(Stream stream, Encoding encoding, string[]) { } }
Such functions as
ASPxScheduler and
DXScheduler for WPF received similar holiday functionality.
How it works in ASPxScheduler, you can see in our
online demo .
In addition to downloading from
iCalendar and
outlook.hol, our scheduler can load and save a collection of holidays in
XML format .
Where else would you need support for holidays in applications? One of the possible scenarios is filtering of unnecessary days when showing a large list of time data. As an example, I will cite the product
XtraCharts , which, following our planners, implemented the support of weekends and holidays to throw out unnecessary dates in the series.
Some analytics
As a bonus, I will cite a few statistical data obtained from the Outlook file. I downloaded the
outlook.hol file with the holidays, filtered the dates to 2010, and visualized the results, while calculating their number per year for different countries.
The following diagram shows the distribution of the number of public holidays by country in 2010:

A complete list of the number of holidays by country is reflected in the legend below:

If you do not take into account the religious holidays, it is not difficult to notice that the leading position in the number of holidays is occupied by such countries as
China ,
Canada and the
United States .
The minimum number of holidays in the
European Union ,
Libya ,
India ,
Malaysia .
Russia occupies the middle position with a value of 12.
Of course, we must understand that these figures show only official holidays and do not reflect the real picture of the total number of days off. So, to draw any conclusions (for example, who is the “most celebrating” country, and who is a “country of a workaholic”) I will give you ... :-)
HAPPY NEW YEAR, EVERYONE!!!