New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@date/holidays-us

Package Overview
Dependencies
Maintainers
0
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@date/holidays-us - npm Package Compare versions

Comparing version 0.3.0 to 0.4.0

23

CHANGES.md

@@ -1,3 +0,22 @@

0.2.0 - 2016/06/30
### 0.4.0 - 2018/07/20
1. update deps
2. switch to JS from CS (except tests)
3. move to node 6+
4. add testing scripts for multiple node versions
5. add code coverage
6. remove gemnasium badge
7. add coveralls badge
8. update tests for 100% code coverage
9. have TravisCI test nodes 6, 8, and 10
### 0.3.0 - 2016/07/22
1. accepted PR from @water42 with easter() implementation
2. split generator into two groups: 1. bank; 2. public.
3. added functions to use one group or the other instead of both
### 0.2.0 - 2016/06/30
1. removed "observed" from holidays which don't have them (copy-paste mistake)

@@ -10,4 +29,4 @@ 2. correct assigning "bank:true" only when the holiday is a weekday

0.1.0 - 2016/06/30
### 0.1.0 - 2016/06/30
1. initial working version with tests

564

lib/index.js

@@ -1,288 +0,358 @@

// Generated by CoffeeScript 1.10.0
var Holidays, gen, generateBankHolidays, generatePublicHolidays, holidays, pushHolidayFromDate;
// TODO:
// should I store all the consistent holiday info objects for reuse?
// For example, all the fixed date holidays and the observed holidays
// have the same info every time. It would store a lot less data overall...
// the variable date holidays only have two info's to store: weekday/weekend.
// Does anyone build up a lot of years of holidays?
// Or, do they only maintain the one they're working with and purge others?
// hmm. I personally work with the current year and sometimes span into another.
// And I'm using it in scripts which run and then exit.
// any feedback on this is welcome.
gen = require('@date/generator')();
// TODO: ??
// put the holiday date calculating functions each in their own package?
// then they can be used separately from this package...
// can then have this package depend on them and use them.
Holidays = require('@date/holidays');
// TODO:
// need a way so they can override the holiday info's.
// should handle this in @date/holidays
holidays = Holidays();
// use `gen` to calculate holiday dates.
var gen = require('@date/generator')()
holidays.newYearsDay = function(year) {
var date;
date = new Date(year, 0, 1);
// use to build default instance and in exported convenience functions.
var Holidays = require('@date/holidays')
// create a default Holidays instance to setup and export.
var holidays = Holidays()
// export a default instance with all the holiday generators.
module.exports = holidays
// add both generators to the default instance.
holidays.add(generateBankHolidays)
holidays.add(generatePublicHolidays)
// add convenience function to provide a Holidays instance with
// only the bank holidays generator.
holidays.bank = function() {
var bankHolidays = Holidays()
bankHolidays.add(generateBankHolidays)
// TODO: add the individual holiday date calculators ...?
return bankHolidays
}
// add convenience function to provide a Holidays instance with
// only the public holidays generator.
holidays.public = function() {
var publicHolidays = Holidays()
publicHolidays.add(generatePublicHolidays)
// TODO: add the individual holiday date calculators ...?
return publicHolidays
}
/*
* Add holiday date calculating functions to the instance so they're
* available individually.
* These are used in the generator functions as well.
*/
holidays.newYearsDay = function newYearsDay(year) {
var date = new Date(year, 0, 1) // january 1st
// add `observed` date if it's a weekend day.
switch (date.getDay()) {
case 0:
date.observed = new Date(year, 0, 2);
break;
case 6:
date.observed = new Date(year - 1, 11, 31);
// when 1, 2, 3, 4, 5 - bank holiday and no observed holiday
case 0: // not a bank holiday, observe it the next day (monday).
date.observed = new Date(year, 0, 2)
break
case 6: // then it's on a saturday, not a bank holiday, observed on friday.
date.observed = new Date(year - 1, 11, 31)
break
}
return date;
};
holidays.valentinesDay = function(year) {
return new Date(year, 1, 14);
};
return date
}
holidays.martinLutherKingDay = function(year) {
return gen.third().monday().january(year);
};
holidays.valentinesDay = function valentinesDay(year) {
// easy, it's always the same date every year.
return new Date(year, 1, 14)
}
holidays.presidentsDay = function(year) {
return gen.third().monday().february(year);
};
holidays.martinLutherKingDay = function martinLutherKingDay(year) {
return gen.third().monday().january(year)
}
holidays.easter = function(year) {
var L, a, b, c, d, date, day, e, f, g, h, i, k, m, month;
a = year % 19;
b = Math.floor(year / 100);
c = year % 100;
d = Math.floor(b / 4);
e = b % 4;
f = Math.floor((b + 8) / 25);
g = Math.floor((b - f + 1) / 3);
h = (19 * a + b - d - g + 15) % 30;
i = Math.floor(c / 4);
k = c % 4;
L = (32 + 2 * e + 2 * i - h - k) % 7;
m = Math.floor((a + 11 * h + 22 * L) / 451);
month = Math.floor(((h + L - 7 * m + 114) / 31) - 1);
day = ((h + L - 7 * m + 114) % 31) + 1;
date = new Date(year, month, day);
return date;
};
holidays.presidentsDay = function presidentsDay(year) {
return gen.third().monday().february(year)
}
holidays.mothersDay = function(year) {
return gen.second().sunday().may(year);
};
holidays.easter = function easter(year) {
// implementation of anonymous gregorian algorithm
var L, a, b, c, d, date, day, e, f, g, h, i, k, m, month
a = year % 19
b = Math.floor(year / 100)
c = year % 100
d = Math.floor(b / 4)
e = b % 4
f = Math.floor((b + 8) / 25)
g = Math.floor((b - f + 1) / 3)
h = (19 * a + b - d - g + 15) % 30
i = Math.floor(c / 4)
k = c % 4
L = (32 + 2 * e + 2 * i - h - k) % 7
m = Math.floor((a + 11 * h + 22 * L) / 451)
month = Math.floor(((h + L - 7 * m + 114) / 31) - 1)
day = ((h + L - 7 * m + 114) % 31) + 1
date = new Date(year, month, day)
return date
}
holidays.memorialDay = function(year) {
return gen.last().monday().may(year);
};
holidays.mothersDay = function mothersDay(year) {
return gen.second().sunday().may(year)
}
holidays.fathersDay = function(year) {
return gen.third().sunday().june(year);
};
holidays.memorialDay = function memorialDay(year) {
return gen.last().monday().may(year)
}
holidays.independenceDay = function(year) {
var date;
date = new Date(year, 6, 4);
holidays.fathersDay = function fathersDay(year) {
return gen.third().sunday().june(year)
}
holidays.independenceDay = function independenceDay(year) {
var date = new Date(year, 6, 4) // july 4th
switch (date.getDay()) {
case 0:
date.observed = new Date(year, 6, 5);
break;
case 6:
date.observed = new Date(year, 6, 3);
// when 1, 2, 3, 4, 5 - bank holiday and no observed holiday.
case 0: // not a bank holiday, observe it the next day (monday).
date.observed = new Date(year, 6, 5)
break
case 6: // then it's on a saturday, not a bank holiday, observed on friday.
date.observed = new Date(year, 6, 3)
break
}
return date;
};
holidays.laborDay = function(year) {
return gen.first().monday().september(year);
};
return date
}
holidays.columbusDay = function(year) {
return gen.second().monday().october(year);
};
holidays.laborDay = function laborDay(year) {
return gen.first().monday().september(year)
}
holidays.halloween = function(year) {
return new Date(year, 9, 31);
};
holidays.columbusDay = function columbusDay(year) {
return gen.second().monday().october(year)
}
holidays.veteransDay = function(year) {
var date;
date = new Date(year, 10, 11);
holidays.halloween = function halloween(year) {
return new Date(year, 9, 31)
}
holidays.veteransDay = function veteransDay(year) {
var date = new Date(year, 10, 11) // november 11th
// add `observed` date if it's a Sunday.
switch (date.getDay()) {
case 0:
date.observed = new Date(year, 10, 12);
// when 1, 2, 3, 4, 5 - bank holiday and no observed holiday.
case 0: // not a bank holiday, observe it the next day (monday).
date.observed = new Date(year, 10, 12)
break
}
return date;
};
holidays.thanksgiving = function(year) {
return gen.fourth().thursday().november(year);
};
return date
}
holidays.christmas = function(year) {
var date;
date = new Date(year, 11, 25);
holidays.thanksgiving = function thanksgiving(year) {
return gen.fourth().thursday().november(year)
}
holidays.christmas = function christmas(year) {
var date = new Date(year, 11, 25) // december 25th
// add `observed` date if it's a weekend day.
switch (date.getDay()) {
case 0:
date.observed = new Date(year, 11, 26);
break;
case 6:
date.observed = new Date(year, 11, 24);
// when 1, 2, 3, 4, 5 - bank holiday and no observed holiday.
case 0: // not a bank holiday, observe it the next day (monday).
date.observed = new Date(year, 11, 26)
break
case 6: // then it's on a saturday, not a bank holiday, observed on friday.
date.observed = new Date(year, 11, 24)
break
}
return date;
};
pushHolidayFromDate = function(array, date, info, observedInfo) {
array.push({
return date
}
// helper function which accepts the calculated holiday date and holiday info's.
// if an observed date was produced then it returns both holidays.
// also helps with the `bank` boolean value.
function makeHoliday(date, info, observedInfo) {
// always make the holiday.
var holiday = {
info: info,
date: {
month: date.getMonth(),
day: date.getDate()
day : date.getDate()
}
});
if (date.observed != null) {
array.push({
info: observedInfo,
date: {
month: date.observed.getMonth(),
day: date.observed.getDate()
}
});
}
};
generatePublicHolidays = function(year) {
var date, holidayArray, info;
holidayArray = [];
date = holidays.valentinesDay(year);
info = {
name: 'Valentine\'s Day',
"public": true
};
pushHolidayFromDate(holidayArray, date, info);
date = holidays.easter(year);
info = {
name: 'Easter',
bank: false
};
pushHolidayFromDate(holidayArray, date, info);
date = holidays.mothersDay(year);
info = {
name: 'Mother\'s Day',
"public": true
};
pushHolidayFromDate(holidayArray, date, info);
date = holidays.fathersDay(year);
info = {
name: 'Father\'s Day',
"public": true
};
pushHolidayFromDate(holidayArray, date, info);
date = holidays.halloween(year);
info = {
name: 'Halloween',
"public": true
};
pushHolidayFromDate(holidayArray, date, info);
return holidayArray;
};
// if the holiday info's `bank` value has a function then
// give it the date so it can evaluate the value.
if ('function' === typeof info.bank) {
info.bank = info.bank(date)
}
generateBankHolidays = function(year) {
var date, holidayArray, info, observedInfo, ref, ref1, ref2, ref3, ref4;
holidayArray = [];
date = holidays.newYearsDay(year);
info = {
name: 'New Year\'s Day'
};
if ((0 < (ref = date.getDay()) && ref < 6)) {
info.bank = true;
// without an observed holiday we return only the main holiday
if (date.observed == null) {
return holiday
}
observedInfo = {
name: 'New Year\'s Day (Observed)',
bank: true
};
pushHolidayFromDate(holidayArray, date, info, observedInfo);
date = holidays.martinLutherKingDay(year);
info = {
name: 'Martin Luther King Jr. Day',
bank: true
};
pushHolidayFromDate(holidayArray, date, info);
date = holidays.presidentsDay(year);
info = {
name: 'President\'s Day'
};
if ((0 < (ref1 = date.getDay()) && ref1 < 6)) {
info.bank = true;
// there's an observed date so return both holidays in an array.
else {
return [
holiday, // main holiday
{ // observed holiday
info: observedInfo,
date: {
month: date.observed.getMonth(),
day : date.observed.getDate()
}
}
]
}
observedInfo = {
name: 'President\'s Day (Observed)',
bank: true
};
pushHolidayFromDate(holidayArray, date, info, observedInfo);
date = holidays.memorialDay(year);
info = {
name: 'Memorial Day',
bank: true
};
pushHolidayFromDate(holidayArray, date, info);
date = holidays.independenceDay(year);
info = {
name: 'Independence Day'
};
if ((0 < (ref2 = date.getDay()) && ref2 < 6)) {
info.bank = true;
}
observedInfo = {
name: 'Independence Day (Observed)',
bank: true
};
pushHolidayFromDate(holidayArray, date, info, observedInfo);
date = holidays.laborDay(year);
info = {
name: 'Labor Day',
bank: true
};
pushHolidayFromDate(holidayArray, date, info);
date = holidays.columbusDay(year);
info = {
name: 'Columbus Day',
bank: true
};
pushHolidayFromDate(holidayArray, date, info);
date = holidays.veteransDay(year);
info = {
name: 'Veterans Day'
};
if ((0 < (ref3 = date.getDay()) && ref3 < 6)) {
info.bank = true;
}
observedInfo = {
name: 'Veterans Day (Observed)',
bank: true
};
pushHolidayFromDate(holidayArray, date, info, observedInfo);
date = holidays.thanksgiving(year);
info = {
name: 'Thanksgiving Day',
bank: true
};
pushHolidayFromDate(holidayArray, date, info);
date = holidays.christmas(year);
info = {
name: 'Christmas Day'
};
if ((0 < (ref4 = date.getDay()) && ref4 < 6)) {
info.bank = true;
}
observedInfo = {
name: 'Christmas Day (Observed)',
bank: true
};
pushHolidayFromDate(holidayArray, date, info, observedInfo);
return holidayArray;
};
}
holidays.add(generateBankHolidays);
// a "@date/holidays generator function".
// it accepts the year and uses it to calculate all the "public" holidays.
function generatePublicHolidays(year) {
holidays.add(generatePublicHolidays);
// return array of generated holidays
return [
makeHoliday(
holidays.valentinesDay(year),
{ name: 'Valentine\'s Day', public: true }
),
module.exports = holidays;
makeHoliday(
holidays.easter(year),
{ name: 'Easter', bank: false }
),
module.exports.bank = function() {
var bankHolidays;
bankHolidays = Holidays();
bankHolidays.add(generateBankHolidays);
return bankHolidays;
};
makeHoliday(
holidays.mothersDay(year),
{ name: 'Mother\'s Day', public: true }
),
module.exports["public"] = function() {
var publicHolidays;
publicHolidays = Holidays();
publicHolidays.add(generatePublicHolidays);
return publicHolidays;
};
makeHoliday(
holidays.fathersDay(year),
{ name: 'Father\'s Day', public: true }
),
makeHoliday(
holidays.halloween(year),
{ name: 'Halloween', public: true }
)
]
}
// helper for holidays with a possible observed date.
// their "is bank holiday" value depends on whether it's a weekday.
function isWeekday(date) {
var day = date.getDay()
return 0 < day && day < 6
}
// a "@date/holidays generator function".
// it accepts the year and uses it to calculate all the "bank" holidays.
function generateBankHolidays(year) {
// return array of generated holidays
return [
newYearsSpecial(year),
makeHoliday(
holidays.martinLutherKingDay(year),
{ name: 'Martin Luther King Jr. Day', bank: true }
),
makeHoliday(
holidays.presidentsDay(year), // Washington's Birthday...
{ name: 'President\'s Day', bank: isWeekday },
{ name: 'President\'s Day (Observed)', bank: true }
),
makeHoliday(
holidays.memorialDay(year),
{ name: 'Memorial Day', bank: true }
),
makeHoliday(
holidays.independenceDay(year),
{ name: 'Independence Day', bank: isWeekday },
{ name: 'Independence Day (Observed)', bank: true }
),
makeHoliday(
holidays.laborDay(year),
{ name: 'Labor Day', bank: true }
),
makeHoliday(
holidays.columbusDay(year),
{ name: 'Columbus Day', bank: true }
),
makeHoliday(
holidays.veteransDay(year),
{ name: 'Veterans Day', bank: isWeekday },
{ name: 'Veterans Day (Observed)', bank: true }
),
makeHoliday(
holidays.thanksgiving(year),
{ name: 'Thanksgiving Day', bank: true }
),
makeHoliday(
holidays.christmas(year),
{ name: 'Christmas Day', bank: isWeekday },
{ name: 'Christmas Day (Observed)', bank: true }
)
]
}
// The New Year's holiday can have an observed date in the previous year.
// That messes with the whole "generate and cache holidays by year" thing.
// This handles it by identifying when that happens and specifying the custom year.
// The @date/holidays package handles the custom year as of v0.3.1.
function newYearsSpecial(year) {
// 1. hold onto the date, we'll need it in #3
var date = holidays.newYearsDay(year)
// 2. do the usual.
var newYears = makeHoliday(
date,
{ name: 'New Year\'s Day', bank: !date.observed },
{ name: 'New Year\'s Day (Observed)', bank: true }
)
// 3. check if the observed date is in the previous year...
if (date.observed && date.observed.getFullYear() < year) {
// specify that year in the observed holiday's date.
newYears[1].date.year = year - 1
}
return newYears
}
{
"name": "@date/holidays-us",
"version": "0.3.0",
"version": "0.4.0",
"description": "USA bank and (some) public holidays",
"main": "lib",
"main": "lib/index.js",
"files": [
"lib/index.js"
],
"keywords": [

@@ -30,7 +33,8 @@ "holidays",

"scripts": {
"compile": "coffee --bare --compile lib",
"clean": "rm -rf lib/*.js",
"prepublish": "npm run compile",
"postpublish": "npm run clean",
"test": "mocha --compilers coffee:coffee-script/register --reporter spec --bail --check-leaks test/lib"
"test": "mocha --require coffeescript/register --reporter spec --bail --check-leaks test/lib/*.coffee",
"test6": "nave use 6 npm test",
"test8": "nave use 8 npm test",
"test10": "nave use 10 npm test",
"test-all": "npm run test6 && npm run test8 && npm run test10",
"coverage": "istanbul cover -x 'build/**' _mocha -- --require coffeescript/register -R spec test/lib/*.coffee"
},

@@ -43,12 +47,13 @@ "repository": {

"devDependencies": {
"coffee-script": "^1.10.0",
"mocha": "^2.3.3"
"coffeescript": "^1.12.7",
"istanbul": "^0.4.5",
"mocha": "^5.2.0"
},
"dependencies": {
"@date/generator": "^0.1.0",
"@date/holidays": "^0.2.0"
"@date/generator": "^0.2.0",
"@date/holidays": "^0.3.2"
},
"engines": {
"node": ">=0.10"
"node": ">=6"
}
}
# @date/holidays-us
[![Build Status](https://travis-ci.org/elidoran/node-date-holidays-us.svg?branch=master)](https://travis-ci.org/elidoran/node-date-holidays-us)
[![Dependency Status](https://gemnasium.com/elidoran/node-date-holidays-us.png)](https://gemnasium.com/elidoran/node-date-holidays-us)
[![npm version](https://badge.fury.io/js/%40date%2Fholidays-us.svg)](http://badge.fury.io/js/%40date%2Fholidays-us)
[![Coverage Status](https://coveralls.io/repos/github/elidoran/node-date-holidays-us/badge.svg?branch=master)](https://coveralls.io/github/elidoran/node-date-holidays-us?branch=master)

@@ -6,0 +6,0 @@ A `@date/holidays` instance with USA public and bank holidays.

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc