Skip to content

Commit

Permalink
Merge pull request #1 from CHECK24/time-fix
Browse files Browse the repository at this point in the history
Calculate ignoring time and timezone values
  • Loading branch information
jdiehl committed May 31, 2016
2 parents 15a6b23 + d8105ff commit 98bbb2a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion holiday-de.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
var year = date.getFullYear();
var tsYearStart = new Date(year, 0, 1).valueOf();
var easterDays = Math.round((calculateEasterSunday(year).valueOf() - tsYearStart) / 86400000);
var diff = Math.round((date.valueOf() - tsYearStart) / 86400000) - easterDays;
var diff = Math.round((new Date(year, month, day).valueOf() - tsYearStart) / 86400000) - easterDays;

function checkVar(name, d) {
return exports.holidays[name] && diff === d ? name : false;
Expand Down
25 changes: 25 additions & 0 deletions test/holiday-de.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,31 @@ describe('#holiday-de', function () {
});
});

describe('neglecting time and time zone', function () {
beforeEach(function () { holiday.setState('by'); });
afterEach(function () { holiday.resetHolidays(); });
it('isHoliday() should not identify holidays one second before they start', function () {
var test = holiday.isHoliday(new Date(2016, 4, 25, 23, 59, 59));
console.assert(test === false, '2016-05-25 23:59:59 should not be a holiday');
});
it('isHoliday() should identify holidays as soon as they start', function () {
var test = holiday.isHoliday(new Date(2016, 4, 26, 0, 0, 0));
console.assert(test, '2016-05-26 00:00:00 should be a holiday');
});
it('isHoliday() should identify holidays at noon', function () {
var test = holiday.isHoliday(new Date(2016, 4, 26, 12, 0, 0));
console.assert(test, '2016-05-26 12:00:00 should be a holiday');
});
it('isHoliday() should identify holidays one second before they are over', function () {
var test = holiday.isHoliday(new Date(2016, 4, 26, 23, 59, 59));
console.assert(test, '2016-05-26 23:59:59 should be a holiday');
});
it('isHoliday() should not identify holidays as soon as they are over', function () {
var test = holiday.isHoliday(new Date(2016, 4, 27, 0, 0, 0));
console.assert(test === false, '2016-05-27 00:00:00 should not be a holiday');
});
});

describe('moment', function () {
beforeEach(function () { holiday.setState('nw'); });
it('isHoliday() should support a moment object', function () {
Expand Down

0 comments on commit 98bbb2a

Please sign in to comment.