-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
exposed holidays as cli/holidays.js module
- Loading branch information
Andrea Giammarchi
committed
Sep 22, 2018
1 parent
54e8f93
commit 43c0e12
Showing
7 changed files
with
81 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
"use strict"; | ||
|
||
var path = require('path'); | ||
|
||
module.exports = function (locale, year) { | ||
var holidays = { | ||
national: [], | ||
regional: [], | ||
year: year || (new Date).getFullYear() | ||
}; | ||
locale.toLowerCase().split(',').forEach(load, holidays); | ||
return holidays; | ||
}; | ||
|
||
function load(lang, year) { | ||
try { | ||
var module = require(path.join('..', 'holidays', lang, 'index.js')); | ||
this.national.push.apply( | ||
this.national, | ||
module.national.map(addYear, this.year).filter(nulled) | ||
); | ||
this.regional.push.apply( | ||
this.regional, | ||
module.regional.map(addYear, this.year).filter(nulled) | ||
); | ||
} catch (notThereYet) {} | ||
} | ||
|
||
function addYear(mmdd) { | ||
return typeof mmdd === 'string' ? | ||
new Date(this + '-' + mmdd) : | ||
mmdd(+this); | ||
} | ||
|
||
function nulled(date) { | ||
return date != null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters