Commit a80c76ee authored by Johannes Bill's avatar Johannes Bill

fixed date comparison, added mocha test

parent b27b6dec
......@@ -7,9 +7,10 @@ var includeString = "810a6deb-46f2-4fa8-b779-bb5c2a6b5577";
var excludeString = "bb74c170-b06f-4d2b-ab88-2f6bf9ce8068";
//var _epochStart = new Date(2014, 3, 0);
var _epochStart = new Date(2014, 4, 20);
var _epochStart = new Date(2014, 0, 0);
//_epochStart.setDate(_epochStart.getDate() - 30);
var _epochEnd = new Date(_epochStart.getTime() + 90 * 24 * 3600000);
//var _epochEnd = new Date(_epochStart.getTime() + 500 * 24 * 3600000);
var _epochEnd = new Date(2016, 0, 0);
var epocheSpan = [_epochStart, _epochEnd];
......@@ -40,7 +41,6 @@ function calculateOpeningHours(json) {
resultExcl.push(getOpeningHours(data, option));
}
resultExcl = tmUtils.orOperator(resultExcl);
var allHolidays = getAllHolidays();
resultIncl = tmUtils.orOperator(resultIncl);
resultIncl = tmUtils.andNotOperator(resultIncl, allHolidays);
......@@ -200,4 +200,5 @@ function getOpeningHoursRepeatable(data) {
}
}
console.log(calculateOpeningHours(require('./testData/testHof.json')));
\ No newline at end of file
var data = calculateOpeningHours(require('./testData/testHof.json'));
console.log(data);
\ No newline at end of file
......@@ -228,7 +228,7 @@ function orOperator(intervals) {
function sort(intervals) {
intervals.sort(function(a, b) {
return a[0] - b[0];
return a[0].getTime() - b[0].getTime();
});
return intervals;
}
......@@ -300,7 +300,7 @@ function invert(interval, epochStart, epochEnd) {
function andNotOperator(interval1, interval2) {
var epochStart = new Date(Math.min(interval1[0][0], interval2[0][0]));
var epochEnd = new Date(Math.min(interval1[interval1.length - 1][1], interval2[interval2.length - 1][1]));
var epochEnd = new Date(Math.max(interval1[interval1.length - 1][1], interval2[interval2.length - 1][1]));
interval2 = invert(interval2, epochStart, epochEnd);
return andOperator(interval1, interval2);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment