moment-feiertage
moment-feiertage is a Moment.js plugin to determine if a date is a german holiday. Holidays are taken from Wikipedia (de). Feel free to contribute!
How to use?
- Add moment-feiertage to your package.json by running
npm install moment-feiertage --save
- Import moment and moment-feiertage
import moment from 'moment'
import 'moment-feiertage'
const moment = require('moment');
const { isHoliday } = require('moment-feiertage');
- call
isHoliday()
on any moment object. Check examples for supported arguments and return values
Examples since version 1.1.0
From version 1.1.0
on isHoliday()
supports Arrays. Pass an empty Array to test agains all states, or pass an Array of state codes (e.g. ['BY', 'SH']
) to test agains passed states. The return value is an Object:
{
allStates: boolean,
holidayName: string,
holidayStates: Array<string>,
testedStates: Array<string>
}
Tests Christmas in all states and all states celebrate this holiday:
const christmasInAllStates = moment('2018-12-25').isHoliday([]);
Tests some holiday in all states but not all states celebrate this holiday:
const someDateInAllStates = moment('2018-11-01').isHoliday([]);
Tests multiple states for a holiday. This checks if the passed states celebrate this holiday:
const someDateInSomeStates = moment('2018-11-01').isHoliday(['BW', 'SH', 'TH']);
Tests some date in all states and no state is celebrating this date:
const someDateInAllStates = moment('2018-12-12').isHoliday([]);
Working Examples since version 1.0.0
const nowIsHoliday = moment().isHoliday();
const someDateIsHoliday = moment('2019-12-25').isHoliday();
const isHolidayInAllStates = moment('2017-08-15').isHoliday();
const isHolidayInBavaria = moment('2017-08-15').isHoliday('BY');
const isHolidayInSaarland = moment('2017-08-15').isHoliday('SL');