Skip to content

Commit

Permalink
exposing closestWeekday
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrea Giammarchi committed Aug 27, 2018
1 parent 585cbda commit a963829
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 23 deletions.
2 changes: 1 addition & 1 deletion coverage/lcov-report/cjs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ <h1>
</div><!-- /wrapper -->
<div class='footer quiet pad2 space-top1 center small'>
Code coverage
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Mon Aug 27 2018 09:44:45 GMT+0200 (CEST)
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Mon Aug 27 2018 10:21:46 GMT+0200 (CEST)
</div>
</div>
<script src="../prettify.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion coverage/lcov-report/cjs/index.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ <h1>
</div><!-- /wrapper -->
<div class='footer quiet pad2 space-top1 center small'>
Code coverage
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Mon Aug 27 2018 09:44:45 GMT+0200 (CEST)
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Mon Aug 27 2018 10:21:46 GMT+0200 (CEST)
</div>
</div>
<script src="../prettify.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion coverage/lcov-report/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ <h1>
</div><!-- /wrapper -->
<div class='footer quiet pad2 space-top1 center small'>
Code coverage
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Mon Aug 27 2018 09:44:45 GMT+0200 (CEST)
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Mon Aug 27 2018 10:21:46 GMT+0200 (CEST)
</div>
</div>
<script src="prettify.js"></script>
Expand Down
32 changes: 12 additions & 20 deletions holidays/us/index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
var utils = require('../utils');

var after = utils.after;
var closestWeekday = utils.closestWeekday;

module.exports = {
national: [
utils.after('Monday', '01-01'),
after('Monday', '01-01'),
MartinLutherKingJr,
utils.before('Monday', '05-31'),
closeTo('07-04'),
utils.after('Monday', '09-01'),
closestWeekday('07-04'),
after('Monday', '09-01'),
Thanksgiving,
'12-25'
],
regional: [
Presidents,
closeTo('04-16'),
closestWeekday('04-16'),
Columbus,
closeTo('11-11'),
closestWeekday('11-11'),
dayAfterThanksgiving
]
};
Expand All @@ -25,37 +28,26 @@ function dayAfterThanksgiving(Y) {
return date;
}

function closeTo(mmdd) {
return function (Y) {
var date = new Date(Y + '-' + mmdd);
if (date.getDay() === 6)
date.setDate(date.getDate() - 1);
else if (date.getDay() === 0)
date.setDate(date.getDate() + 1);
return date;
};
}

function Columbus(Y) {
var date = utils.after('Monday', '10-01')(Y);
var date = after('Monday', '10-01')(Y);
date.setDate(date.getDate() + 7);
return date;
}

function MartinLutherKingJr(Y) {
var date = utils.after('Monday', '01-01')(Y);
var date = after('Monday', '01-01')(Y);
date.setDate(date.getDate() + 7 * 2);
return date;
}

function Presidents(Y) {
var date = utils.after('Monday', '02-01')(Y);
var date = after('Monday', '02-01')(Y);
date.setDate(date.getDate() + 7 * 2);
return date;
}

function Thanksgiving(Y) {
var date = utils.after('Thursday', '11-01')(Y);
var date = after('Thursday', '11-01')(Y);
date.setDate(date.getDate() + 7 * 3);
return date;
}
12 changes: 12 additions & 0 deletions holidays/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module.exports = {
after: after,
ascension: ascension,
before: before,
closestWeekday: closestWeekday,
corpusChristi: corpusChristi,
easter: easter,
pentecost: pentecost,
Expand All @@ -22,6 +23,17 @@ function before(day, fn) {
return _find(day, fn, -1);
}

function closestWeekday(mmdd) {
return function (Y) {
var date = new Date(Y + '-' + mmdd);
if (date.getDay() === 6)
date.setDate(date.getDate() - 1);
else if (date.getDay() === 0)
date.setDate(date.getDate() + 1);
return date;
};
}

function corpusChristi(Y) {
var date = easter(Y);
date.setDate(date.getDate() + 7 * 8);
Expand Down

0 comments on commit a963829

Please sign in to comment.