Commit 964b2601 authored by Johannes Bill's avatar Johannes Bill

fixed dateview asstring

parent 778847d8
{ {
"restApiHost": "127.0.0.1", "restApiHost": "127.0.0.1",
"restApiPort": 3001, "restApiPort": 3001,
"mysqlConfig": { "mysqlConfig": {
"host": "127.0.0.1", "host": "127.0.0.1",
"user": "root", "user": "root",
"password": "bla", "password": "bla",
"database": "holidays" "database": "holidays"
} }
} }
\ No newline at end of file
...@@ -2,6 +2,8 @@ var moment = require('moment'); ...@@ -2,6 +2,8 @@ var moment = require('moment');
moment.lang("de"); moment.lang("de");
var twoHours = 1000 * 3600 * 2;
function createWeekView(dataObj, now) { function createWeekView(dataObj, now) {
var data = dataObj.intervals; var data = dataObj.intervals;
var holidays = dataObj.holidays; var holidays = dataObj.holidays;
...@@ -287,6 +289,7 @@ function asString(data, now) { ...@@ -287,6 +289,7 @@ function asString(data, now) {
var open = false; var open = false;
var nowT = now.getTime(); var nowT = now.getTime();
var idx = 0; var idx = 0;
var first, second;
while (nowT >= data[idx][0].getTime() && idx < data.length) { while (nowT >= data[idx][0].getTime() && idx < data.length) {
if (data[idx][1].getTime() >= nowT) if (data[idx][1].getTime() >= nowT)
...@@ -295,27 +298,34 @@ function asString(data, now) { ...@@ -295,27 +298,34 @@ function asString(data, now) {
} }
if (open) { if (open) {
idx--; idx--;
return { if(data[idx][1].getTime() - nowT <= twoHours)
isOpen: true, first = "Jetzt noch geöffnet";
asString: ["Jetzt geöffnet", "bis " + moment(data[idx][1]).format("LT")] else first = "Jetzt geöffnet";
};
second = "bis " + moment(data[idx][1]).format("LT");
} }
else { else {
var retStr = "Jetzt nicht geöffnet"; first = "Jetzt nicht geöffnet";
if (idx == data.length) { if (idx == data.length) {
return { second = "nächster Öffnungstermin unbekannt";
isOpen: false,
asString: [retStr, "nächster Öffnungstermin unbekannt"]
}
} }
else { else {
var nextM = moment(data[idx][0]); var nextM = moment(data[idx][0]);
return { if(data[idx][0].getTime() - nowT <= twoHours) {
isOpen: false, second = "bald wieder geöffnet, ab " + nextM.format("LT");
asString: [retStr, "wieder geöffnet am " + nextM.format("dddd") + ", " + nextM.format("l") + " ab " + nextM.format("LT")] }
}; else if(compareDate(now, data[idx][0]) === 0) {
second = "wieder geöffnet ab " + nextM.format("LT")
}
else {
second = "wieder geöffnet am " + nextM.format("dddd") + ", " + nextM.format("l") + " ab " + nextM.format("LT");
}
} }
} }
return {
isOpen: open,
asString: [first, second]
}
} }
module.exports.asString = asString; module.exports.asString = asString;
......
...@@ -38,6 +38,7 @@ module.exports.getData = function (now, cb) { ...@@ -38,6 +38,7 @@ module.exports.getData = function (now, cb) {
cnt++; cnt++;
var view = dateView.getView(dataObj, now); var view = dateView.getView(dataObj, now);
var asString = dateView.asString(dataObj, now); var asString = dateView.asString(dataObj, now);
asString = asString.asString.join(", ");
result.push('<div class="name">' + name + "</div> " + asString + view); result.push('<div class="name">' + name + "</div> " + asString + view);
} }
if (--iters == 0) { if (--iters == 0) {
......
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