Commit b47512ad authored by Johannes Bill's avatar Johannes Bill

refactor branch

parent 90b80c60
...@@ -2,6 +2,7 @@ var holidayMapping = require('./holidayMapping.json'); ...@@ -2,6 +2,7 @@ var holidayMapping = require('./holidayMapping.json');
var easterSunday = require('./easterSunday'); var easterSunday = require('./easterSunday');
var restRequest = require('./restRequests'); var restRequest = require('./restRequests');
var easterSundays = {};
var fixedHolidays = { var fixedHolidays = {
101: "0101", 101: "0101",
106: "0601", 106: "0601",
...@@ -25,9 +26,27 @@ var variableOffsets = { ...@@ -25,9 +26,27 @@ var variableOffsets = {
602: 50 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() { function getEasterSunday() {
if (!easterSundays[year]) if (!easterSundays[year])
...@@ -58,13 +77,13 @@ function Holidays(year) { ...@@ -58,13 +77,13 @@ function Holidays(year) {
var holidays = getFixedHolidays(fixedHolidays); var holidays = getFixedHolidays(fixedHolidays);
holidays = getVariableHolidaysMap(variableOffsets, holidays); holidays = getVariableHolidaysMap(variableOffsets, holidays);
console.log(holidays);
function getIsAugsburg(plz) { function getIsAugsburg(plz) {
return !!(86150 <= plz && plz <= 86199); return !!(86150 <= plz && plz <= 86199);
} }
function getRegionOptions(plz, cb) { function getRegionOptions(plz, epochSpan, cb) {
var blnd; var blnd;
var options = { var options = {
isKath: false, isKath: false,
...@@ -86,6 +105,11 @@ function Holidays(year) { ...@@ -86,6 +105,11 @@ function Holidays(year) {
cb(null, options); 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) { ...@@ -96,7 +120,7 @@ function Holidays(year) {
return cb(null, keys); return cb(null, keys);
} }
getRegionOptions(plz, function(err, options) { getRegionOptions(plz, epochSpan, function(err, options) {
console.log(options); console.log(options);
if(err) return cb(err); if(err) return cb(err);
var blnd = options.blnd; 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