ods-holidays
v1.0.7
Published
API for calculating correct past and future dates of government recognized holidays in Ontario
Downloads
9
Readme
Ontario Digital Serice Public Holidays Calulator
Setup
Getting Started
require('ods-holidays')
How the library works
When you require ods-holidays
within your project you have access to two functions.
holidaysList(year)
This function takes any year past, present, or future as it's sole argument and returns an array of objects containing all public holidays for that year.
ex: holidays.holidaysList(1999)
would return:
[
{
date: "01-01-1999",
english: "New Year\'s Day",
french: "Jour de l\'An",
type: "federal",
stat: true
},
{
date: "02-15-1999",
english: "Family Day",
french: "Journée Familiale",
type: "provincial",
stat: true
},
{
date: "04-02-1999",
english: "Good Friday",
french: "Vendredi saint",
type: "federal",
stat: true
},
{
date: "04-05-1999",
english: "Easter Monday",
french: "Lundi de Pâques",
type: "provincial",
stat: false
},
{
date: "05-24-1999",
english: "Victoria Day",
french: "Fête de Victoria",
type: "federal",
stat: true
},
{
date: "07-01-1999",
english: "Canada Day",
french: "Fête du Canada",
type: "federal",
stat: true
},
{
date: "08-02-1999",
english: "Civic Holiday",
french: "Premier lundi d\'août",
type: "provincial",
stat: false
},
{
date: "09-06-1999",
english: "Labour Day",
french: "Fête du travail",
type: "federal",
stat: true
},
{
date: "10-11-1999",
english: "Thanksgiving",
french: "Action de grâce",
type: "federal",
stat: true
},
{
date: "11-11-1999",
english: "Remembrance Day",
french: "Jour du Souvenir",
type: "federal",
stat: false
},
{
date: "12-25-1999",
english: "Christmas Day",
french: "Noël",
type: "federal",
stat: true,
serviceHoliday: "12-27-1999"
},
{
date: "12-26-1999",
english: "Boxing Day",
french: "Lendemain de Noël",
type: "provincial",
stat: true,
serviceHoliday: "12-28-1999"
},
]
Occassionaly there is an additional property added to any holiday object of serviceHoliday
. This returns a date for which government services are unavailable. This occurs when the offical date of the holiday falls on a Saturday or a Sunday.
In our above example both Christmas and Boxing Day have this property. This is because in 1999 Christmas and Boxing Day occurred on Saturday and Sunday respectively. So government services would be unavailable on the 27th and 28th.
isHoliday(date)
This function is currently used to return whether a given date (in the format MM-DD-YYYY) is a government holiday. This informs services that government offices et al would be closed on these dates.
It will return {isHoliday: true}
if the given date is a holiday or a service holiday, otherwise it returns {isHoliday: false}
.
Running tests
npm test
will run through all the tests in this project using the node_modules mocha/chai.
If you want to run a specific set of tests you will need to make sure that mocha is installed globally.
npm install mocha -g
With this installed, mocha test
will run all the tests and using the -g flag will look for tests with the given string argument. For example
mocha -g 'Holiday Controller'
will run all the tests with Holiday Controller in the describe blocks.
Contributing:
Coding Standards
The project mainly follows the google javascript standards with a few modifications. Filenames are camelcase when required and there is a soft limit of 80 chars and a hard limit of 120 chars for non test code. There is also a .eslintrc file that can be hooked into text editors and ide's to get them to follow our standard.
Filenames
The preferred way to create new files is to use the following format
{resource_name}.{module_type}.js
However if you are working with files named with camelCase, please use that style for those resources.
So as an example, let us use holiday as an example.
The preferred way would look like:
holiday.view.js
hoiday.controller.js
All test files must be placed in the test
folder. Test files append .test
before the .js
so a test for the model would be:
holiday.model.test.js