Commit b47512ad authored by Johannes Bill's avatar Johannes Bill

refactor branch

parent 90b80c60
......@@ -2,6 +2,7 @@ var holidayMapping = require('./holidayMapping.json');
var easterSunday = require('./easterSunday');
var restRequest = require('./restRequests');
var easterSundays = {};
var fixedHolidays = {
101: "0101",
106: "0601",
......@@ -25,9 +26,27 @@ var variableOffsets = {
602: 50
};
function Holidays(year) {
var holidayToSpecificMap = (function() {
var regionH = holidayMapping["region"];
var hMap = {};
for(var rKey in regionH) {
var rH = regionH[rKey];
for(var cKey in rH) {
var hArray = rH[cKey];
for (var i = 0; i < hArray.length; i++) {
var hd = hArray[i];
if(!hMap[hd])
hMap[hd] = {region: [], special: []};
if(cKey == "default") hMap[hd].region.push(rKey);
else hMap[hd].special.push(cKey);
}
}
}
return hMap;
}());
console.log(holidayToSpecificMap);
var easterSundays = {};
function Holidays(year) {
function getEasterSunday() {
if (!easterSundays[year])
......@@ -58,13 +77,13 @@ function Holidays(year) {
var holidays = getFixedHolidays(fixedHolidays);
holidays = getVariableHolidaysMap(variableOffsets, holidays);
console.log(holidays);
function getIsAugsburg(plz) {
return !!(86150 <= plz && plz <= 86199);
}
function getRegionOptions(plz, cb) {
function getRegionOptions(plz, epochSpan, cb) {
var blnd;
var options = {
isKath: false,
......@@ -86,6 +105,11 @@ function Holidays(year) {
cb(null, options);
}
});
}
function isInEpochSpan(date, epochSpan) {
var dateTime = date.getTime();
return epochSpan[0].getTime() <= dateTime && dateTime <= epochSpan[1].getTime()
}
......@@ -96,7 +120,7 @@ function Holidays(year) {
return cb(null, keys);
}
getRegionOptions(plz, function(err, options) {
getRegionOptions(plz, epochSpan, function(err, options) {
console.log(options);
if(err) return cb(err);
var blnd = options.blnd;
......
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