Commit 7a7989f0 authored by Johannes Bill's avatar Johannes Bill

created lib folder

implemented test with database data

implemented test with database data

refactor

added express test

added express test

added express test

created lib folder

added Mocha Test

added Mocha Test
parent 81ef072c
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<style>
* {
box-sizing: border-box;
}
.main {
border-collapse: collapse;
width: 400px;
table-layout: fixed;
}
.td {
background-color: #e8e8e8;
border: 1px solid #d9d9d9;
display: inline-block;
}
</style>
</head>
<body>
<table class="main">
<tr class="tr">
<td class="td" style="width: 25%">qe</td>
<td class="td" style="width: 25%">qe</td>
<td class="td" style="width: 25%">qe</td>
<td class="td" style="width: 25%">qe</td>
</tr>
<tr class="tr">
<td class="td" style="width: 15%">qe</td>
<td class="td" style="width: 35%">qe</td>
<td class="td" style="width: 10%">qe</td>
<td class="td" style="width: 40%">qe</td>
</tr>
</table>
</body>
</html>
\ No newline at end of file
......@@ -3,21 +3,30 @@ var Holidays = require('./holidays');
var now = new Date();
var holidaysGetter = new Holidays(now.getFullYear());
var includeString = "810a6deb-46f2-4fa8-b779-bb5c2a6b5577";
var excludeString = "bb74c170-b06f-4d2b-ab88-2f6bf9ce8068";
var epochSpan = testEpochSpan();
var _epochStart = new Date();
_epochStart = new Date(_epochStart.getFullYear(), _epochStart.getMonth(), _epochStart.getDate());
//var _epochStart = new Date(2014, 0, 0);
_epochStart.setDate(_epochStart.getDate() - 30);
var _epochEnd = new Date(_epochStart.getTime() + 130 * 24 * 3600000);
//var _epochEnd = new Date(2015, 0, 0);
var epochSpan = [_epochStart, _epochEnd];
function setEpocheSpan(_epocheSpan) {
epochSpan = _epocheSpan;
}
function testEpochSpan() {
var _epochStart = new Date();
_epochStart = new Date(_epochStart.getFullYear(), _epochStart.getMonth(), _epochStart.getDate());
_epochStart.setDate(_epochStart.getDate() - 30);
var _epochEnd = new Date(_epochStart.getTime() + 130 * 24 * 3600000);
return [_epochStart, _epochEnd];
}
function calculateOpeningHours(json) {
var includeString = "810a6deb-46f2-4fa8-b779-bb5c2a6b5577";
var excludeString = "bb74c170-b06f-4d2b-ab88-2f6bf9ce8068";
var jsonIncl = json[includeString];
var jsonExcl = json[excludeString];
if (!jsonIncl) {
throw new Error('no openinghours model found');
}
var resultIncl = [];
var resultExcl = [];
......@@ -29,25 +38,36 @@ function calculateOpeningHours(json) {
option = getOption(data);
if (option == "holiday")
holidayIncl = holidayIncl.concat(getHolidays(data));
else if (option == "vacation") {
resultExcl.push(getOpeningHours(data, option));
}
// else if (option == "vacation") {
// resultExcl.push(getOpeningHours(data, option));
// }
else
resultIncl.push(getOpeningHours(data, option));
}
for (key in jsonExcl) {
data = jsonExcl[key];
option = getOption(data);
resultExcl.push(getOpeningHours(data, option));
if (jsonExcl) {
for (key in jsonExcl) {
data = jsonExcl[key];
option = getOption(data);
resultExcl.push(getOpeningHours(data, option));
}
resultExcl = tmUtils.orOp(resultExcl);
}
resultExcl = tmUtils.orOperator(resultExcl);
var allHolidays = getAllHolidays();
resultIncl = tmUtils.orOperator(resultIncl);
resultIncl = tmUtils.andNotOperator(resultIncl, allHolidays);
resultIncl = tmUtils.orOperator([resultIncl, holidayIncl]);
return tmUtils.andNotOperator(resultIncl, resultExcl);
allHolidays = tmUtils.andOp(allHolidays, [epochSpan]);
holidayIncl = tmUtils.andOp(holidayIncl, [epochSpan]);
resultIncl = tmUtils.orOp(resultIncl);
resultIncl = tmUtils.andNotOp(resultIncl, allHolidays);
resultIncl = tmUtils.orOp([resultIncl, holidayIncl]);
var result = resultIncl;
if (jsonExcl)
result = tmUtils.andNotOp(resultIncl, resultExcl);
return result;
}
function getDaySpan(data) {
......@@ -63,7 +83,7 @@ function getDaySpan(data) {
case 10:
return [1, 6];
default:
console.error("Invalid day option");
throw new Error("Invalid day option: " + dayoption);
}
}
......@@ -75,6 +95,8 @@ function parseTime(time) {
}
}
//TODO now.getFullYear muss verschwinden, Jahreswechsel!!!!
function parseDate(date, addOneDay) {
if (date.length == 0)
return null;
......@@ -90,9 +112,7 @@ function parseDate(date, addOneDay) {
function getHolidays(data) {
var option = data["option"]["0"];
if (option != "holiday") {
console.error("data is no holiday");
console.error(data);
return null;
throw new Error('not holiday: ' + option);
}
var timeSpan = getTimeSpan(data);
......@@ -118,6 +138,7 @@ function getAllHolidays() {
function getDateSpan(data) {
var startDate = parseDate(data["opening_day_from"]) || epochSpan[0];
var endDate = parseDate(data["opening_day_to"], true) || epochSpan[1];
//TODO start und enddate vertauschen, falls enddate < startdate
return [startDate, endDate];
}
......@@ -141,8 +162,10 @@ function getOpeningHours(data, option) {
return getOpeningHoursRepeatable(data);
case "vacation":
return getOpeningHoursVacation(data);
case "":
return [];
default:
console.error("option %s not supported", option);
throw new Error("option not supported: " + option);
return [];
}
}
......@@ -183,13 +206,12 @@ function getOpeningHoursRepeatable(data) {
case 28:
return tmUtils.standardFromTillDay(daySpan, timeSpan, dateSpan, epochSpan, repeatOption);
default:
console.error("invalid repeatoption");
throw new Error("invalid repeatoption");
}
}
}
module.exports.getData = function(json) {
return calculateOpeningHours(json);
};
module.exports.getData = calculateOpeningHours;
module.exports.setEpocheSpan = setEpocheSpan;
var moment = require('moment');
moment.lang("de");
function createWeekView(data, now) {
var noOfDays = 7;
var offset = 3;
var startDate = new Date(now.getFullYear(), now.getMonth(), now.getDate() - offset);
var endDate = new Date(now.getFullYear(), now.getMonth(), now.getDate() + noOfDays - offset);
var oHours = getDataFromTo(data, startDate, endDate);
var oHours = transformData(data, startDate, endDate);
var maxNumber = getMaxNoOfItemsPerDay(oHours);
var tableWidth = 2 * maxNumber;
var content = '<table class="weekview-table>"';
var content = '<div class="weekview-container"><table class="weekview-table">';
content += '<tbody>';
for(var i = 0; i < noOfDays; i++) {
for (var i = 0; i < noOfDays; i++) {
var day = oHours[i];
content += '<tr class="weekview-tr">';
content += '<td class="weekview-td-first">' + formatDate(day.date) + '</td>';
......@@ -29,7 +31,7 @@ function createWeekView(data, now) {
}
content += '</tbody>';
content += '</table>';
content += '</table></div>';
return content;
}
......@@ -41,16 +43,17 @@ function createMonthView(data, now, monthOffset) {
startDate.setDate(2 - startDate.getDay());
var endDate = new Date(now.getFullYear(), currentMonth + 1, 1);
if(endDate.getDay() != 1)
if (endDate.getDay() != 1)
endDate.setDate(9 - endDate.getDay());
var oHours = getDataFromTo(data, startDate, endDate);
//TODO: only transform once for 3 month view
var oHours = transformData(data, startDate, endDate);
var content = '<div class="monthview-maindiv">';
content += '<div class="monthview-month">' + moment(monthDate).format("MMMM") + '</div>';
content += '<table class="monthview-table"><thead class="monthview-thead"><tr>';
for(var i = 0; i < 7; i++) {
for (var i = 0; i < 7; i++) {
content += '<th class="monthview-th">' + moment(oHours[i].date).format("dd") + '</th>';
}
content += '</tr></thead>';
......@@ -58,13 +61,13 @@ function createMonthView(data, now, monthOffset) {
for (var i = 0; i < oHours.length; i++) {
var day = oHours[i];
if(i % 7 == 0)
if (i % 7 == 0)
content += '<tr class="monthview-tr">';
if(day.date.getMonth() == currentMonth) {
if (day.date.getMonth() == currentMonth) {
var cls;
var tooltip;
if(day.oHours.length == 0) {
if (day.oHours.length == 0) {
tooltip = "";
cls = " monthview-empty";
}
......@@ -76,16 +79,16 @@ function createMonthView(data, now, monthOffset) {
tooltip.push(formatTime(e[0]) + " - " + formatTime(e[1]));
}
tooltip = tooltip.join("<br>");
tooltip = ' data-uk-tooltip title="' + tooltip +'"';
tooltip = ' data-uk-tooltip title="' + tooltip + '"';
}
content += '<td class="monthview-td' + cls +'"'+ tooltip+'>' + moment(day.date).format("D") + '</td>';
content += '<td class="monthview-td' + cls + '"' + tooltip + '>' + moment(day.date).format("D") + '</td>';
}
else {
content += '<td class="monthview-td monthview-exclude"></td>';
}
if(i % 7 == 6)
if (i % 7 == 6)
content += '</tr>';
}
......@@ -95,13 +98,21 @@ function createMonthView(data, now, monthOffset) {
function create3MonthView(data, now) {
var content = '<div class="monthview-container">';
for(var i = 0; i < 3; i++) {
for (var i = 0; i < 3; i++) {
content += createMonthView(data, now, i);
}
content += '</div>';
return content;
}
function getView(data, now) {
var content = '<div class="view-container">';
content += createWeekView(data, now);
content += create3MonthView(data, now);
content += '</div>';
return content;
}
function getMaxNoOfItemsPerDay(oHours) {
var max = 0;
for (var i = 0; i < oHours.length; i++) {
......@@ -112,14 +123,14 @@ function getMaxNoOfItemsPerDay(oHours) {
}
function formatDate(date) {
return moment(date).format("dd L");
return moment(date).format("dd ll");
}
function formatTime(date) {
return moment(date).format("HH:mm");
}
function getDataFromTo(data, startDate, endDate) {
function transformData(data, startDate, endDate) {
var dataIdx = 0;
var result = [];
var curDate = new Date(startDate);
......@@ -127,6 +138,7 @@ function getDataFromTo(data, startDate, endDate) {
var oHours = [];
while (dataIdx < data.length) {
var comp = compareDate(data[dataIdx][0], curDate);
//TODO: split midnight
if (comp < 0)
dataIdx++;
else if (comp == 0) {
......@@ -153,25 +165,11 @@ function compareDate(date1, date2) {
return diff;
}
function parseJSON(json) {
var result = JSON.parse(json);
for (var i = 0; i < result.length; i++) {
var elem = result[i];
elem[0] = new Date(elem[0]);
elem[1] = new Date(elem[1]);
}
return result;
function getPropperEpochSpan(now) {
var epochStart = new Date(now.getFullYear(), now.getMonth(), - 10);
var epochEnd = new Date(now.getFullYear(), now.getMonth() + 3, 1);
return [epochStart, epochEnd];
}
moment.lang("de");
var jsonInput = require('./jsonInput');
var fs = require('fs');
var data = jsonInput.getData(require('./../testData/testHof.json'));
console.log(data);
var weekView = create3MonthView(data, new Date(), 0);
console.log();
fs.writeFile(process.env["HOME"] + '/Desktop/bla.html', weekView, function(err) {
console.log(err);
});
\ No newline at end of file
module.exports.getView = getView;
module.exports.getPropperEpochSpan = getPropperEpochSpan;
\ No newline at end of file
......@@ -43,7 +43,9 @@ function Holidays(year) {
};
var easterSundays = {
2014: new Date(2014, 3, 20)
2014: new Date(2014, 3, 20),
2015: new Date(2015, 3, 5),
2016: new Date(2016, 2, 27)
};
function getEasterSunday() {
......@@ -52,7 +54,7 @@ function Holidays(year) {
function getFixedHolidays(fixedHolidays, object) {
var result = object || {};
for(var key in fixedHolidays) {
for (var key in fixedHolidays) {
var dateString = fixedHolidays[key];
var date = parseInt(dateString.slice(0, 2));
var month = parseInt(dateString.slice(2, 4));
......@@ -64,7 +66,7 @@ function Holidays(year) {
function getVariableHolidaysMap(offsets, object) {
var result = object || {};
var easterDate = getEasterSunday();
for(var key in offsets) {
for (var key in offsets) {
var offset = offsets[key];
result[key] = new Date(year, easterDate.getMonth(), easterDate.getDate() + offset);
}
......@@ -74,15 +76,15 @@ function Holidays(year) {
var holidays = getFixedHolidays(fixedHolidays);
holidays = getVariableHolidaysMap(variableOffsets, holidays);
this.getHoliday = function(id) {
if(id == 0) {
this.getHoliday = function (id) {
if (id == 0) {
var result = [];
for(var key in holidays) {
for (var key in holidays) {
result.push(holidays[key]);
}
return result;
}
if(id in holidays)
if (id in holidays)
return [holidays[id]];
console.error("invalid holiday id " + id);
return null;
......
......@@ -44,7 +44,7 @@ function standardFromTillDay(daySpan, timeSpan, dateSpan, epochSpan, daysDistanc
var dayTo = daySpan[1];
var timeFrom = timeSpan[0];
var timeUntil = timeSpan[1];
var epochStart = dateSpan[0];
var epochStart = new Date(dateSpan[0]);
var epochEnd = dateSpan[1];
var firstDays = _standard(dayFrom, timeFrom, timeUntil, epochStart, epochEnd, daysDistance);
......@@ -61,29 +61,7 @@ function standardFromTillDay(daySpan, timeSpan, dateSpan, epochSpan, daysDistanc
}
}
result = sort(result);
result = andOperator(result, [epochSpan]);
return result;
}
function cyclic(day, noInMonth, timeFrom, timeUntil, epochStart, epochEnd) {
var result = [];
epochStart = new Date(epochStart);
while(true) {
var startDate = _getNextNoInMonthOccurence(day, epochStart, noInMonth);
startDate.setHours(timeFrom.h);
startDate.setMinutes(timeFrom.m);
var endDate = new Date(startDate);
endDate.setHours(timeUntil.h);
endDate.setMinutes(timeUntil.m);
if(endDate.getTime() > epochEnd.getTime())
break;
else {
result.push([startDate, endDate]);
epochStart = new Date(endDate);
epochStart.setDate(epochStart.getDate() + 1);
}
}
result = andOp(result, [epochSpan]);
return result;
}
......@@ -135,28 +113,10 @@ function cyclicFromTillDay(daySpan, noInMonth, timeSpan, dateSpan, epochSpan) {
}
}
result = andOperator(result, [epochSpan]);
result = andOp(result, [epochSpan]);
return result;
}
/*function _cyclicFromTillDayOld(dayFrom, dayTill, noInMonth, timeFrom, timeUntil, epochStart, epochEnd) {
var firstDays = cyclic(dayFrom, noInMonth, timeFrom, timeUntil, epochStart, epochEnd);
var result = firstDays.slice();
for(var offset = 1; offset <= dayTill - dayFrom; offset++) {
for(var i = 0; i < firstDays.length; i++) {
var start = new Date(firstDays[i][0]);
var end = new Date(firstDays[i][1]);
start.setDate(start.getDate() + offset);
end.setDate(end.getDate() + offset);
if(end <= epochEnd)
result.push([start, end]);
}
}
sort(result);
return result;
}*/
function _getNextNoInMonthOccurence(day, startDate, noInMonth) {
startDate = new Date(startDate);
......@@ -218,7 +178,7 @@ function dateSpan(dateSpan) {
];
}
function orOperator(intervals) {
function orOp(intervals) {
var result = [];
for(var i = 0; i < intervals.length; i++) {
result = result.concat(intervals[i]);
......@@ -250,7 +210,7 @@ function mergeOverlaps(interval) {
return interval;
}
function andOperator(interval1, interval2) {
function andOp(interval1, interval2) {
var result = [];
var i = 0;
......@@ -305,12 +265,19 @@ function invert(interval, epochStart, epochEnd) {
* @param interval2
* @returns {*}
*/
function andNotOperator(interval1, interval2) {
function andNotOp(interval1, interval2) {
if(!(interval1 && interval1[0] && interval1[0][0])) {
return [];
}
if(!(interval2 && interval2[0] && interval2[0][0])) {
return interval1;
}
var epochStart = new Date(Math.min(interval1[0][0], interval2[0][0]));
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);
return andOp(interval1, interval2);
}
function validate(interval) {
......@@ -327,9 +294,9 @@ function validate(interval) {
module.exports.standardFromTillDay = standardFromTillDay;
module.exports.cyclicFromTillDay = cyclicFromTillDay;
module.exports.singleDay = singleDay;
module.exports.orOperator = orOperator;
module.exports.andOperator = andOperator;
module.exports.andNotOperator = andNotOperator;
module.exports.orOp = orOp;
module.exports.andOp = andOp;
module.exports.andNotOp = andNotOp;
module.exports.mergeOverlaps = mergeOverlaps;
module.exports.sort = sort;
module.exports.dateSpan = dateSpan;
......
var expect = require("chai").expect;
var dateArray = require('../lib/dateArray');
describe("dateArray" ,function() {
describe("calculateOpeningHours", function() {
it("should equal", function() {
var data = require('./testData/testHof.json');
var epocheSpan = [new Date(2014,0,1), new Date(2015,0,1)];
dateArray.setEpocheSpan(epocheSpan);
var oHours =dateArray.getData(data);
var result = JSON.stringify(oHours);
expect(result).to.equal(require('./testData/testHofResult.json')['data']);
})
})
});
\ No newline at end of file
var expect = require("chai").expect;
var fs = require('fs');
var dateArray = require('../lib/dateArray');
var dateView = require('../lib/dateView');
describe("dateView" ,function() {
describe("calculateOpeningHours", function() {
it("should equal", function() {
var data = require('./testData/testHof.json');
var now = new Date(2014, 4, 1);
var epocheSpan = dateView.getPropperEpochSpan(now);
dateArray.setEpocheSpan(epocheSpan);
var oHours =dateArray.getData(data);
var view = dateView.getView(oHours, now);
console.log(view);
var viewRef = fs.readFileSync(__dirname + '/testData/testHofView.html', {
encoding: "utf8"
});
expect(view).to.equal(viewRef);
})
})
});
\ No newline at end of file
var expect = require("chai").expect;
describe("bla" ,function() {
describe("muh", function() {
it("should maeh", function() {
var date1 = new Date();
var date2 = new Date(date1.getTime());
console.log(date1);
console.log(date2);
console.log(date1 < date2);
expect(date1.getTime()).to.equal(date2.getTime());
})
})
});
\ No newline at end of file
{
"810a6deb-46f2-4fa8-b779-bb5c2a6b5577": {
"0": {
"option": {
"0": "default"
},
"dayoption": {
"0": "9"
},
"repeatoption": {
"0": ""
},
"holidayoption": {
"0": ""
},
"opening_day_from": "",
"opening_day_to": "",
"opening_from": "09:00",
"opening_to": "17:00"
},
"1": {
"option": {
"0": "default"
},
"dayoption": {
"0": "2"
},
"repeatoption": {
"0": ""
},
"holidayoption": {
"0": ""
},
"opening_day_from": "",
"opening_day_to": "",
"opening_from": "9:00",
"opening_to": "18:00"
},
"2": {
"option": {
"0": "repeatable"
},
"dayoption": {
"0": "9"
},
"repeatoption": {
"0": "1"
},
"holidayoption": {
"0": ""
},
"opening_day_from": "",
"opening_day_to": "",
"opening_from": "10:00",
"opening_to": "13:00"
},
"3": {
"option": {
"0": "holiday"
},
"dayoption": {
"0": "1"
},
"repeatoption": {
"0": ""
},
"holidayoption": {
"0": "602"
},
"opening_day_from": "",
"opening_day_to": "",
"opening_from": "13:00",
"opening_to": "15:00"
}
},
"bb74c170-b06f-4d2b-ab88-2f6bf9ce8068": {
"0": {
"option": {
"0": "vacation"
},
"dayoption": {
"0": ""
},
"repeatoption": {
"0": "3"
},
"holidayoption": {
"0": ""
},
"opening_day_from": "27.05",
"opening_day_to": "04.06",
"opening_from": "",
"opening_to": ""
},
"1": {
"option": {
"0": "default"
},
"dayoption": {
"0": "2"
},
"repeatoption": {
"0": "3"
},
"holidayoption": {
"0": ""
},
"opening_day_from": "01.01",
"opening_day_to": "",
"opening_from": "10:00",
"opening_to": "12:30"
},
"2": {
"option": {
"0": "repeatable"
},
"dayoption": {
"0": "3"
},
"repeatoption": {
"0": "2"
},
"holidayoption": {
"0": ""
},
"opening_day_from": "",
"opening_day_to": "",
"opening_from": "",
"opening_to": ""
}
}
}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
......@@ -3,12 +3,13 @@
"version": "0.0.0",
"main": "holidays.js",
"dependencies": {
"express": "^4.4.5",
"moment": "^2.7.0"
},
"devDependencies": {
"chai": "^1.9.1",
"node-mysql": "^0.3.7"
"ejs": "^1.0.0",
"express": "*",
"mysql": "*"
},
"author": "",
"license": "ISC",
......
var express = require('express');
var path = require('path');
var routes = require('./routes/index');
var app = express();
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.use('/', express.static(path.join(__dirname, 'public')));
app.use('/', routes);
app.use(function (req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
if (app.get('env') === 'development') {
app.use(function (err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: err
});
});
}
app.use(function (err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: {}
});
});
app.set('port', process.env.PORT || 3000);
var server = app.listen(app.get('port'), function () {
console.log('Express server listening on port ' + server.address().port);
});
\ No newline at end of file
var mysql = require('mysql');
var dateArray = require('../lib/dateArray');
var dateView = require('../lib/dateView');
var connection = mysql.createConnection({
host: 'localhost',
user: 'read',
password: 'read',
database: 'regiostart'
});
connection.connect();
module.exports.getData = function(now, cb) {
var epocheSpan = dateView.getPropperEpochSpan(now);
// console.log(now);
// console.log(epocheSpan);
dateArray.setEpocheSpan(epocheSpan);
connection.query('SELECT name, elements FROM cms_zoo_item WHERE type = "company"', function(err, rows) {
var result = [];
var cnt = 0;
for (var i = 0; i < rows.length; i++) {
var obj = JSON.parse(rows[i].elements);
var name = rows[i].name;
try {
var data = dateArray.getData(obj);
if (data.length > 0) {
cnt++;
var view = dateView.getView(data, now);
result.push('<div class="name">'+name+"</div> "+view);
}
}
catch (err) {
}
}
console.log("Count: %d", cnt);
cb(result.join('<br>'));
});
};
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
var express = require('express');
var router = express.Router();
var db = require('../dataBaseQuery');
router.get('/', function(req, res) {
var dateString = req.query.date;
var now;
if(dateString && dateString.length == 8) {
var year = parseInt(dateString.slice(0,4));
var month = parseInt(dateString.slice(4,6));
var date = parseInt(dateString.slice(6,8));
now = new Date(year, month - 1, date);
}
else {
now = new Date();
}
var time0 = process.hrtime();
db.getData(now, function(result) {
res.render('index', { body: result });
var time1 = process.hrtime(time0);
console.log('Time in ms: ' + (1000 * time1[0] + time1[1] * 1e-6));
});
});
module.exports = router;
<h1><%= message %></h1>
<h2><%= error.status %></h2>
<pre><%= error.stack %></pre>
<!DOCTYPE html>
<html>
<head>
<title>Views</title>
<link rel="stylesheet" href="uikit.min.css"/>
<script src="jquery.min.js"></script>
<script src="uikit.min.js"></script>
<style>
body {
padding: 30px;
}
.monthview-filled {
background-color: lightgreen;
}
.monthview-empty {
background-color: lightcoral;
}
.name {
font-size: 20px;
}
</style>
</head>
<body>
<%- body %>
</body>
</html>
var mysql = require('mysql');
var dateArray = require('../lib/dateArray');
var dateView = require('../lib/dateView');
var fs = require('fs');
var tmUtils = require('../lib/timeUtils');
var connection = mysql.createConnection({
host: 'localhost',
user: 'read',
password: 'read',
database: 'regiostart'
});
connection.connect();
connection.query('SELECT name, elements FROM cms_zoo_item WHERE type = "company"', function (err, rows) {
var cntGood = 0;
var cntBad = 0;
for (var i = 0; i < rows.length; i++) {
var json = rows[i].elements;
var obj = JSON.parse(json);
var name = rows[i].name;
try {
var result = dateArray.getData(obj);
tmUtils.validate(result);
}
catch (err) {
console.log(err, name);
var result = [];
fs.writeFileSync(process.env["HOME"] + '/Desktop/oHours/invalid/' + name + '.json', json);
}
if (result.length > 0) {
// console.log(name);
// console.log(JSON.stringify(result));
cntGood++;
}
else {
cntBad++;
}
}
console.log(cntGood, cntBad);
});
connection.end();
\ No newline at end of file
var dateView = require('../lib/dateView');
var dateArray = require('../lib/dateArray');
var fs = require('fs');
var now = new Date(2014, 4, 1);
dateArray.setEpocheSpan(dateView.getPropperEpochSpan(now));
var data = dateArray.getData(require('././testHof.json'));
console.log(data);
var view = dateView.getView(data, now, 0);
fs.writeFile(process.env["HOME"] + '/Desktop/bla.html', view, function (err) {
if (err) console.log(err);
else console.log("file saved");
});
\ No newline at end of file
{
"f86608fb-16aa-4c70-9d57-0b5cac1a9618": {
},
"4ae7b6cb-07e8-4184-a00b-9db001f55bd3": {
"0": {
"value": ""
}
},
"f64563c6-c102-4836-a5f7-8f9246fcceef": {
"option": {
"0": "direktvermarkter-mit-geschaeft",
"1": "premium"
},
"select": "1"
},
"f62d066f-bf0d-42e2-a7ae-6f926fbb49d7": {
"0": {
"value": ""
}
},
"915f382b-51fc-48ba-93e0-152040f8f0e4": {
"0": {
"value": ""
}
},
"1b99ac64-7879-4802-80d9-0de99613efc9": {
"option": {
"0": "premium"
},
"check": "1"
},
"8cf3f417-4d1c-4795-87de-42124dcb2c20": {
"option": {
"0": "premium"
},
"select": "1"
},
"f118eeff-e254-4155-8e23-8149cb8b5eea": {
"0": {
"value": "Testhof"
}
},
"dbc68015-df76-42ed-a033-503b87e35685": {
"check": "1"
},
"0b13b5c0-bec6-445c-bdf2-e201ba0d43e4": {
"file": "",
"title": "",
"link": "",
"target": "0",
"rel": "",
"lightbox_image": "",
"spotlight_effect": "",
"caption": ""
},
"17709bb7-acf7-4ef5-8b26-4ed4fe63f8c9": {
"0": {
"value": ""
}
},
"3d305054-e356-4c09-8f4c-7795433a4589": {
"file": "",
"title": "",
"link": "",
"target": "0",
"rel": "",
"lightbox_image": "",
"spotlight_effect": "",
"caption": ""
},
"e8c1fdc9-50e0-4a9b-994a-f48f738dac64": {
},
"ed9cdd4c-ae8b-4ecb-bca7-e12a5153bc02": {
"0": {
"value": "Testen auf dem Testhof"
}
},
"514ccde0-0a79-4594-8b72-b906ee4cede9": {
"0": {
"opening_day": "",
"opening_from": "",
"opening_to": ""
}
},
"810a6deb-46f2-4fa8-b779-bb5c2a6b5577": {
"0": {
"option": {
"0": "default"
},
"dayoption": {
"0": "9"
},
"repeatoption": {
"0": ""
},
"holidayoption": {
"0": ""
},
"opening_day_from": "",
"opening_day_to": "",
"opening_from": "09:00",
"opening_to": "17:00"
},
"1": {
"option": {
"0": "default"
},
"dayoption": {
"0": "2"
},
"repeatoption": {
"0": ""
},
"holidayoption": {
"0": ""
},
"opening_day_from": "",
"opening_day_to": "",
"opening_from": "9:00",
"opening_to": "18:00"
},
"2": {
"option": {
"0": "repeatable"
},
"dayoption": {
"0": "9"
},
"repeatoption": {
"0": "1"
},
"holidayoption": {
"0": ""
},
"opening_day_from": "",
"opening_day_to": "",
"opening_from": "10:00",
"opening_to": "13:00"
},
"3": {
"option": {
"0": "holiday"
},
"dayoption": {
"0": "1"
},
"repeatoption": {
"0": ""
},
"holidayoption": {
"0": "602"
},
"opening_day_from": "",
"opening_day_to": "",
"opening_from": "13:00",
"opening_to": "15:00"
}
},
"bb74c170-b06f-4d2b-ab88-2f6bf9ce8068": {
"0": {
"option": {
"0": "vacation"
},
"dayoption": {
"0": ""
},
"repeatoption": {
"0": "3"
},
"holidayoption": {
"0": ""
},
"opening_day_from": "27.05",
"opening_day_to": "04.06",
"opening_from": "",
"opening_to": ""
},
"1": {
"option": {
"0": "default"
},
"dayoption": {
"0": "2"
},
"repeatoption": {
"0": "3"
},
"holidayoption": {
"0": ""
},
"opening_day_from": "01.01",
"opening_day_to": "",
"opening_from": "10:00",
"opening_to": "12:30"
},
"2": {
"option": {
"0": "repeatable"
},
"dayoption": {
"0": "3"
},
"repeatoption": {
"0": "2"
},
"holidayoption": {
"0": ""
},
"opening_day_from": "",
"opening_day_to": "",
"opening_from": "",
"opening_to": ""
}
},
"7ac7d682-2862-443b-83bd-8a3cf837ad8e": {
"option": {
"0": "0"
}
},
"6b3b589d-8060-4193-92b9-ce430d96cfdd": {
"0": {
"value": "Immer und t\u00e4glich ge\u00f6ffnet, au\u00dfer es ist niemand da."
}
},
"65359d5a-faca-46b8-8644-767d382d8b9b": {
"option": {
"0": "hinweis"
},
"check": "1"
},
"533ea2dd-e37d-4add-aa73-ad8419040c22": {
"0": {
"value": "Immer und t\u00e4glich ge\u00f6ffnet, au\u00dfer es ist niemand da."
}
},
"6d9ab971-f969-499b-bb6b-9b87b601a961": {
"check": "1"
},
"f67464f3-4475-46a9-a262-11c8a777865d": {
"0": {
"value": "Regoistart GmbH"
}
},
"1d0a9c64-78d4-4767-8617-c8a3a66fc770": {
"0": {
"value": ""
}
},
"05192b86-fc84-43cb-81d3-ab804086a873": {
"0": {
"value": ""
}
},
"d230a60f-0016-4180-b83a-13e4fd938328": {
"0": {
"value": "regionalkauf.com"
}
},
"c70daef6-ffee-40ef-ba29-3d0065a5aaf5": {
},
"a77f06fc-1561-453c-a429-8dd05cdc29f5": {
"0": {
"value": "<p>Bienenhonig, Met, Propolis, Bl\u00fctenpollen. sm\u00f6rrebr\u00f6d, smoerrebroed roemtoemtoemt\u00f6m.<\/p>"
}
},
"1a85a7a6-2aba-4480-925b-6b97d311ee6c": {
"0": {
"value": "<p>Bienenhonig, Met, Propolis, Bl\u00fctenpollen. supercalafragalisticexpialadoshus, s\u00fcpercalafragalisticexpialad\u00f6shus<\/p>"
}
},
"efd91873-dce0-48fd-b40e-5bc0e9599f3e": {
},
"9ca9fc28-03f8-472d-b49f-8e2513cc8740": {
"file": "images\/regionalkaufapp\/unternehmen\/logo_basis.png",
"title": "",
"link": "",
"target": "0",
"rel": "",
"lightbox_image": "",
"spotlight_effect": "",
"caption": "",
"width": 144,
"height": 145
},
"ffcc1c50-8dbd-4115-b463-b43bdcd44a57": {
"file": "images\/regionalkaufapp\/unternehmen\/logo_basis.png",
"title": "",
"link": "",
"target": "0",
"rel": "",
"lightbox_image": "",
"spotlight_effect": "",
"caption": "",
"width": 144,
"height": 145
},
"e8f08959-19ff-4cfa-ba37-bc42414eeb45": {
"value": "\/allgemein",
"title": "Die Bilder sind in Vorbereitung."
},
"051452fe-692b-4ce2-8567-7dc4d0343fee": {
"url": "",
"width": "640",
"height": "360",
"autoplay": "0"
},
"b68108e0-e49b-420d-97ec-d7c88af2b01a": {
"file": "",
"hits": "0",
"download_limit": "",
"size": 0
},
"92fda174-119b-4ee7-b14c-98c7f65224de": {
},
"4339a108-f907-4661-9aab-d6f3f00e736e": {
"0": {
"value": "Dr.Theobald-Schrems-Stra\u00dfe 4"
}
},
"ea0666d7-51e3-4e52-8617-25e3ad61f8b8": {
"0": {
"value": "93055"
}
},
"90a18889-884b-4d53-a302-4e6e4595efa0": {
"0": {
"value": "Regensburg"
}
},
"160bd40a-3e0e-48de-b6cd-56cdcc9db892": {
"location": "49.0146337, 12.111873899999978"
},
"9ff517f0-d029-4e85-a411-fdb2bbae3b8c": {
"location": "49.0146337, 12.111873899999978"
},
"33bfd53b-1f42-4628-bb3d-461cacecdd84": {
"0": {
"value": "12.111873899999978, 49.0146337"
}
},
"7516ee89-8702-4675-806b-58fe5bc56305": {
},
"b870164b-fe78-45b0-b840-8ebceb9b9cb6": {
"0": {
"value": "0941 56959760"
}
},
"272860a4-9ba0-4303-b2d3-77abb8d6fd42": {
"0": {
"value": "0941 56959768"
}
},
"5dcfa5ab-3769-4c5e-8cd2-1ac91643be70": {
"0": {
"value": "0941 56959768"
}
},
"8a91aab2-7862-4a04-bd28-07f1ff4acce5": {
"0": {
"value": "0941 56959769"
}
},
"3f15b5e4-0dea-4114-a870-1106b85248de": {
"0": {
"value": "mb@regiostart.com",
"text": "",
"subject": "",
"body": ""
}
},
"0b3d983e-b2fa-4728-afa0-a0b640fa34dc": {
"0": {
"value": "http:\/\/regiostart.com",
"text": "",
"target": "1",
"custom_title": "",
"rel": ""
}
},
"b7628b63-d551-4b14-ac70-27cf0c6e95fc": {
"0": {
"value": "http:\/\/myreg.io\/g"
}
},
"2081965c-c781-4ae1-99c3-54b959145cfe": {
"value": "1"
},
"8eeeb531-0dc3-415a-8f4a-c7f88d1ac627": {
"value": "1"
},
"9bd1d374-6a54-4054-be1e-87839eb24fb6": {
},
"7056f1d2-5253-40b6-8efd-d289b10a8c69": {
"item": {
"0": "2423"
}
},
"6eaab8b7-b4f5-4d3c-8193-db3542aec0a5": {
},
"c59ac5ce-2011-44b9-846f-e9cb73857b33": {
},
"e2221aa5-853b-4a8c-aeb1-53a97efa6995": {
},
"9eeb4b7d-f289-4137-91ea-5275bb3376a7": {
},
"23685df7-81bb-4c25-a14a-18e2c42a4caf": {
},
"cf6dd846-5774-47aa-8ca7-c1623c06e130": {
"votes": "1",
"value": "5.0000"
},
"cffd7b0a-317a-4cf9-852e-65fd31526a53": {
"votes": "1"
}
}
\ No newline at end of file
......@@ -6,20 +6,37 @@ was passiert bei der zeitumstellung?
falls oeffnungszeit z.b. von 21:00 bis 4:00 muss bei 0:00 getrennt werden
saisonal,urlaub etc ueber neujahr? 23.12.2014 - 10.01.2015????
Funktionen:
openNow(json, now, gemeindezeugs, lang, asString)
openNow(json, now, regionalCode, lang, asString)
asString=1
asString
Falls geoffnet:
<WochenTag>, jetzt bis <UhrZeit> geoeffnet.
Falls nicht geoffnet:
Am <WochenTag> nicht geoffnet. Wieder geoeffnet am <WochendTag, Datum> ab <UhrZeit>.
asString=0
asLiteral
{
open: true|false,
date: bis|ab
}
asIndexJson
0 { opening-from:
opening-to:
opening-day:}
1 { .... }
...
asIndex
Array(day => ""
open => ""
close => "")
openingHoursView(json, now, regionalCode, lang)
-->html string
\ No newline at end of file
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