npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

moment-feiertage

v2.0.9

Published

Moment.js Plugin for german holidays; check if a given Date is a german holiday

Downloads

1,635

Readme

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?

  1. 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.
  2. Import moment from moment-feiertage like you would from the original Moment.js package. moment-feiertage exports the original moment object with extended functionality.
// Typescript
import * as moment from 'moment-feiertage';

// node
const moment = require('moment-feiertage');
  1. Check the examples below for functionality, supported arguments and return values.

getAllStateCodes()

since 2.0.0

const codes = moment.getAllStateCodes();
/* returns ['BW','BY','BE','BB','HB','HH','HE','MV','NI','NW','RP','SL','SN','ST','SH','TH']*/

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);
/* returns {
  'Neujahrstag': {
    date: moment('2020-01-01'),
    state: [] // nationwide holiday
  },
  'Heilige Drei Könige': {
    date: moment('2020-01-06')
    state: ['BW', 'BY', 'ST'] // only these states celebrate
  },
  [ ... ]
} */

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, // default false
  holidayName: string, // default: ''
  holidayStates: Array<string>, // default: []
  testedStates: Array<string> // default: ...allStates
}
  • 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 holiday
  • holidayStates 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([]);
/* returns {
  allStates: true,
  holidayName: '1. Weihnachtsfeiertag',
  holidayStates: ...allStates,
  testedStates: ...allStates
}*/
const christmasInSomeStates = moment('2018-11-01').isHoliday(['BW', 'SH']);
/* returns {
  allStates: true,
  holidayName: '1. Weihnachtsfeiertag',
  holidayStates: [ 'BW', 'SH' ],
  testedStates: [ 'BW', 'SH' ]
}*/
const someDateInAllStates = moment('2018-11-01').isHoliday([]);
/* returns {
  allStates: false,
  holidayName: 'Allerheiligen',
  holidayStates: [ 'BW', 'BY', 'NW', 'RP', 'SL' ],
  testedStates: ...allStates
}*/
const noHolidayDateInAllStates = moment('2018-12-12').isHoliday([]);
/* returns {
  allStates: false,
  holidayName: '',
  holidayStates: [],
  testedStates: ...allStates
}*/

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();
// returns name of holiday (string) if date is a holiday
// retruns false (boolean) if date is not a holiday

const someDateIsHoliday = moment('2019-12-25').isHoliday();
// returns '1. Weihnachtsfeiertag' - is a holiday in all states

const isHolidayInAllStates = moment('2017-08-15').isHoliday();
// returns false - is not a holiday in all states

const isHolidayInBavaria = moment('2017-08-15').isHoliday('BY');
// returns false - is not a holiday in BY

const isHolidayInSaarland = moment('2017-08-15').isHoliday('SL');
// returns 'Mariä Himmelfahrt' - is a holiday in 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

  • Google Places Api: https://github.com/DaniSchenk/moment-feiertage/issues/17#issuecomment-780445461 provided by @t-wark

Contribute

  1. fork
  2. npm install and add your desired version of Moment.js: npm install moment --no-save
  3. code
  4. npm run build: linting, formating, building, testing
  5. PR