Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

date-holidays-parser

commenthol784kISC3.4.7TypeScript support: included

parser for worldwide holidays

holidays, parser, world

readme

date-holidays-parser

parser for world-wide holidays

NPM version Build Status

This module provides a parser for date-holidays which does calculation of holidays dates for various countries, states and regions by type while considering the applicable timezone.

The features are:

  • calculation of public, bank and observance holidays for different countries, state, region, following ISO 3166-2
  • consideration of timezones for holiday checks
  • consideration of start and end time dependent on timezone
  • substitute days
  • multi-language support for all holiday names
  • setting of custom holidays
  • uses own grammar for calculation of days
  • support for islamic calendar from 1970 to 2080 (*islamic dates might not be correct as they are subject to the sighting of the moon)
  • support for hebrew calendar from 1970 to 2100
  • support for chinese calendar

Happy holidays!

Table of Contents

Usage

const data = require('date-holidays/data/holidays.json')
const Holidays = require('date-holidays-parser')
const hd = new Holidays(data)

// get supported countries
hd.getCountries()
/*>
{ AD: 'Andorra',
  ...
  US: 'United States' }
*/

// get supported states e.g. for US
hd.getStates('US')
/*>
{ al: 'Alabama',
  ...
  wy: 'Wyoming' }
*/

// get supported regions e.g. for US, Lousiana
hd.getRegions('US', 'la')
/*>
{ no: 'New Orleans' }
*/

// initialize holidays for US, Lousiana, New Orleans
hd.init('US', 'la', 'no')
// or using a new instance
hd = new Holidays('US', 'la', 'no')

// get all holidays for the year 2016
hd.getHolidays(2016)
/*>
[ { date: '2016-01-01 00:00:00',
    start: Fri Jan 01 2016 00:00:00 GMT-0600 (CST),
    end: Sat Jan 02 2016 00:00:00 GMT-0600 (CST),
    name: 'New Year\'s Day',
    type: 'public' },
  ...
  { date: '2016-11-24 00:00:00',
    start: Thu Nov 24 2016 00:00:00 GMT-0600 (CST),
    end: Fri Nov 25 2016 00:00:00 GMT-0600 (CST),
    name: 'Thanksgiving Day',
    type: 'public' },
  ...
  { date: '2016-12-26 00:00:00',
    start: Mon Dec 26 2016 00:00:00 GMT-0600 (CST),
    end: Tue Dec 27 2016 00:00:00 GMT-0600 (CST),
    substitute: true,
    name: 'Christmas Day (substitute day)',
    type: 'public' } ]
*/

// check if date is a holiday while respecting timezones
hd.isHoliday(new Date('2016-02-09 00:00:00 GMT+0000'))
//> false
hd.isHoliday(new Date('2016-02-09 10:00:00 GMT-0600'))
/*>
{ date: '2016-02-09 00:00:00',
  start: Tue Feb 09 2016 00:00:00 GMT-0600 (CST),
  end: Wed Feb 10 2016 00:00:00 GMT-0600 (CST),
  name: 'Mardi Gras',
  type: 'public' }
*/

Holiday object

getHolidays() as well as a matching isHoliday() call return either a list or a single holiday object which consists of:

  • {String} date - ISO Date String of (start)-date in local format
  • {Date} start - start date of holiday
  • {Date} end - end date of holiday
  • {String} name - name of holiday using language (if available)
  • {String} type - type of holiday public|bank|school|optional|observance
  • {Boolean} substitute - (optional) if true holiday substitutes another holiday`
  • {String} note - (optional) note`

Dates

The date String represents the start date of the holiday in ISO format without timezone. This string it intended for information only.

start and end are the start/end date of the holiday within the selected timezone of the country, state, region.

Name

The name names the holiday in the local language of the selected country, state, region. The applied language(s) can be requested using getLanguages().

The language can be changed using the setLanguages() method. In case that not translation is available a fall-back to the next given language will be made. E.g. local language is "fr", setLanguages('nl') was called. For all holidays where no dutch translation is available the French version will be used instead.

All holiday names should support an English translation.

Types of holidays

Currently the following type with their meaning are supported

type meaning
public public holiday
bank bank holiday, banks and offices are closed
school school holiday, schools are closed
optional majority of people take a day off
observance optional festivity, no paid day off

Additionally a note field is sometimes available for further clarification.

API

See Holidays API for further information.

Browser

This project also runs in all modern browsers. See ./examples/browser

Browser Version Notes
Chrome >=45
Firefox >=45
Safari >=10
Edge >=13
IE >=10 needs polyfill core-js/es6

Please do not forget to set the correct charset!

<html>
<head>
  <!-- set page-wide -->
  <meta charset="UTF-8">
  ...
</head>
<body>
  ...
  <!-- or per script -->
  <script src="your-bundle.js" charset="UTF-8"></script>

Testing was done with zuul. For local browser tests run npm run zuul -- --local 3000 and open http://localhost:3000/__zuul.

requires manual install of

npm i zuul@3 browserify@10

Data

All data for the holidays of the different countries is contained in ./data/holidays.json. For changing holiday data edit the appropriate country in ./data/countries. Any details on structure and available grammar for holiday attribution is described in holidays.yaml specification.

Contribution and License Agreement

If you contribute code to this project, you are implicitly allowing your code to be distributed under the ISC license. You are also implicitly verifying that all code is your original work or correctly attributed with the source of its origin and license.

License

Copyright (c) 2015-present commenthol (ISC License)

See LICENSE for more information.

References

changelog

Changelog

3.4.6 (2024-12-12)

  • chore: reliably run postbuild script 5d2ae8d
  • fix(#62): es2015 issue remove optional chaining operator 126f2ff

3.4.5 (2024-11-26)

  • chore: test with node@22 deprecate node@16 e99dcb9
  • fix: issue date-holidays#484 after unset rule isHoliday throws 4b11197

3.4.3 (2022-12-13)

  • fix: cjs bundling with rollup 44ef857 Revert back to rollup@2

3.4.2 (2022-11-20)

  • chore: bump dependencies ea6e424 Use rollup@3 for bundling

3.4.0 (2022-05-21)

  • docs: add persian calendar e9c793d
  • feat: support for jalaali calendar 1bb11b7

3.3.0 (2022-02-25)

  • chore: use github actions c0175ef
  • feat: rule dateDir omit weekdays 98d526a
  • feat: rule if holiday 93edc4d
  • refactor: use console.error instead of log 7ca3f8e
  • refactor: change let to const 3a05ff5
  • test: removing comments with console.log 785f1c0
  • "the current year" 0eabcc6
  • fix typos in docs e3bd683
  • fix(CalEventMap): 2nd date in calendar can't be reached 5fd6102
  • Tevet once/twice edge case tests 1b1270f
  • Tevet edge case tests ccb49c0
  • empty lines between tests 28dfc44

3.2.4 (2021-12-28)

  • docs: update API documentation 16f0058
  • test: use local dates for TZ tests de4c653
  • chore: refactor hijri calendar script 247c1fe
  • test: hebrew calendar Adar date tests ca00b2d
  • fix: hebrew month AdarII a02fee7
  • fix: Some hebrew dates don't show up in a gregorian year c478182

3.2.3 (2021-11-16)

  • updated README.md: set valid url for Holidays API b73dda1

3.2.2 (2021-08-08)

  • chore: fix problematic astronomia export a441627
  • chore: update travis badge 907c81f

3.2.1 (2021-06-15)

  • fix: clone dates before timezone shift cf53ed2
  • fix: remove use strict a3fb423

3.2.0 (2021-05-22)

  • fix: esm astronomia imports e2bde32
  • fix: ts export namespace f4f7be2
    to use ts types in your typescript projects use

    import Holidays, { HolidaysTypes } from 'date-holidays-parser'
  • fix: package.json module for angular 8b02806

3.1.0 (2021-05-03)

  • chore: changelog 69bc4c2
  • fix: remove optional chaining operator to work with node@12 ecb84ce
  • feat: DateFn cache results a74c02d
  • test: custom attributes 2e9b2a7
  • fix: typings 114416b
  • feat: methods to get, set, unset holiday rules 7775351
  • refactor: calevent.filterActive b49d26b
  • fix: isHoliday(date) may be a string type 7db3d6b

3.0.2 (2021-05-02)

3.0.0 (2021-03-27)

2.1.0 (2021-02-13)

  • fix: parsing rule for solstice, equinox c569bb1
  • feat: new rule since and prior to 2056356

2.0.1 (2021-02-07)

  • fix: Month spelling for equinox, solstice c8c0c58
  • docs: fix weekday spelling 9acf59a
  • fix: Allow correct spelled weekdays 28a1635

1.6.0 (2021-01-04)

  • fix: Fix collision in PostRule with Array prototype overrides 7f69163
  • feat: replace lodash function to reduce bundle size 516966a

1.5.0

  • fix: sort by rule length 45f4bcf
  • fix: add sort by rule 280729a
  • chore: update fixtures 732ff84
  • chore: remove node@8 from travis 9c38d33
  • fix: sort order by date and type db70108
  • docs: clarify substitute, if, then rule 463c3e6
  • test: fix tests c74a7ce
  • feat: return rule in getHolidays b146eb3

1.4.3

  • feat: return rule in getHolidays 31b6b48

1.4.2

  • fix: shift timezone for isHolidays c337ec1

1.4.1

1.4.0

1.3.2

  • fix: set country, state as object bcb427e
  • refactor: make isActive static 58c98d9

1.3.1

1.3.0

1.2.3

  • remove node 4 from travis 3eb8411
  • fix issue multiple types 1153d9d
  • add testcase for state name translations b500227

1.2.2

1.2.1

1.2.0

1.1.1

1.1.0

1.0.1