fixed wrong date interpretation

This commit is contained in:
Timo Volkmann 2020-06-17 18:25:21 +02:00
parent a7baa4b626
commit 8fedd36e22

View File

@ -58,9 +58,7 @@ module.exports = function (dbConn) {
// CALCULATE AVERAGE SCORE // CALCULATE AVERAGE SCORE
reg.score = calculateAverage(reg.scores) reg.score = calculateAverage(reg.scores)
}) })
return { return _.orderBy(regions, ({ score }) => score || 0, 'desc') //.filter(el => !_.isNaN(el.score))
results: _.orderBy(regions, ({ score }) => score || 0, 'desc') //.filter(el => !_.isNaN(el.score))
}
} }
function calculateAverage(scores) { function calculateAverage(scores) {
@ -126,14 +124,14 @@ module.exports = function (dbConn) {
from: {}, from: {},
to: {} to: {}
} }
if (_.isNumber(from) && _.isNumber(to)) { if (_.isNumber(from) && _.isNumber(to)) {
let dateFrom = moment(from).toDate() let dateFrom = new Date(from)
let dateTo = moment(to).toDate() fromAndTo.from.day = dateFrom.getDate()
fromAndTo.from.month = dateFrom.getMonth() fromAndTo.from.month = dateFrom.getMonth() + 1
fromAndTo.to.month = dateTo.getMonth() let dateTo = new Date(to)
fromAndTo.from.day = dateFrom.getDay() fromAndTo.to.day = dateTo.getDate()
fromAndTo.to.day = dateTo.getDay() fromAndTo.to.month = dateTo.getMonth() + 1
//console.log(dateFrom.toUTCString(), dateTo.toUTCString())
if (moment(dateFrom).add(23, 'hours').isAfter(moment(dateTo))) throw new Error("ERR: 'to' must be at least one day after 'from'.") if (moment(dateFrom).add(23, 'hours').isAfter(moment(dateTo))) throw new Error("ERR: 'to' must be at least one day after 'from'.")
} else { } else {
// this block to still support old query syntax, validating from and to parameter // this block to still support old query syntax, validating from and to parameter
@ -163,7 +161,7 @@ module.exports = function (dbConn) {
score: (region[type][period.month - 1] === null || searchLowParam === null) ? null : sc, score: (region[type][period.month - 1] === null || searchLowParam === null) ? null : sc,
days: period.days days: period.days
} }
console.log(res); //console.log(res);
return res return res
}) })