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
. Moment.js is a peer dependency, so don't forget to install it, if you haven't already. - Import
moment
from moment-feiertage like you would from the original Moment.js package. moment-feiertage exports the original moment object with extended functionality.
import * as moment from 'moment-feiertage';
const moment = require('moment-feiertage');
- Check the examples below for functionality, supported arguments and return values.
getAllStateCodes()
since 2.0.0
const codes = moment.getAllStateCodes();
getHolidaysByYear(year: number)
since 2.0.0
Returns an object containing all holidays of a year. Every holiday has a date
and a state
property. date
is holding a moment object representing the holidays date. It's a nationwide holiday, if the state
value is an empty Array.
const codes = moment.getHolidaysByYear(2020);
isHoliday(states: Array)
since 1.1.0
From version 1.1.0
on isHoliday()
supports Arrays. Pass an empty Array to test against all states, or pass an Array of state codes (e.g. ['BY', 'SH']
). The return value is an Object:
{
allStates: boolean,
holidayName: string,
holidayStates: Array<string>,
testedStates: Array<string>
}
allStates
is true
, if the checked date is a nationwide holiday, even if not all states are checked because of the states
param.holidayName
contains the name of the holidayholidayStates
contains the states, where this holiday is celebrated. If states
param is provided, holidayStates
contains only a subset of states
testedStates
is the same as the states
param. If states
param is []
, isHoliday will check against all states by default
const christmasInAllStates = moment('2018-11-01').isHoliday([]);
const christmasInSomeStates = moment('2018-11-01').isHoliday(['BW', 'SH']);
const someDateInAllStates = moment('2018-11-01').isHoliday([]);
const noHolidayDateInAllStates = moment('2018-12-12').isHoliday([]);
isHoliday(state?: string)
since 1.0.0
Since version 1.0.0
isHoliday()
checks if there's a holiday at a moment object. A state code can be provided optionally.
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');
State codes
BW = Baden-Württemberg
BY = Bayern
BE = Berlin
BB = Brandenburg
HB = Bremen
HH = Hamburg
HE = Hessen
MV = Mecklenburg-Vorpommern
NI = Niedersachsen
NW = Nordrhein-Westfalen
RP = Rheinland-Pfalz
SL = Saarland
SN = Sachsen
ST = Sachsen-Anhalt
SH = Schleswig-Holstein
TH = Thüringen
Mappings
Contribute
- fork
npm install
and add your desired version of Moment.js: npm install moment --no-save
- code
npm run build
: linting, formating, building, testing- PR