fixed wrong date interpretation
This commit is contained in:
parent
0586a7a0ba
commit
0d82057383
@ -58,9 +58,7 @@ module.exports = function (dbConn) {
|
||||
// CALCULATE AVERAGE SCORE
|
||||
reg.score = calculateAverage(reg.scores)
|
||||
})
|
||||
return {
|
||||
results: _.orderBy(regions, ({ score }) => score || 0, 'desc') //.filter(el => !_.isNaN(el.score))
|
||||
}
|
||||
return _.orderBy(regions, ({ score }) => score || 0, 'desc') //.filter(el => !_.isNaN(el.score))
|
||||
}
|
||||
|
||||
function calculateAverage(scores) {
|
||||
@ -126,14 +124,14 @@ module.exports = function (dbConn) {
|
||||
from: {},
|
||||
to: {}
|
||||
}
|
||||
|
||||
if (_.isNumber(from) && _.isNumber(to)) {
|
||||
let dateFrom = moment(from).toDate()
|
||||
let dateTo = moment(to).toDate()
|
||||
fromAndTo.from.month = dateFrom.getMonth()
|
||||
fromAndTo.to.month = dateTo.getMonth()
|
||||
fromAndTo.from.day = dateFrom.getDay()
|
||||
fromAndTo.to.day = dateTo.getDay()
|
||||
let dateFrom = new Date(from)
|
||||
fromAndTo.from.day = dateFrom.getDate()
|
||||
fromAndTo.from.month = dateFrom.getMonth() + 1
|
||||
let dateTo = new Date(to)
|
||||
fromAndTo.to.day = dateTo.getDate()
|
||||
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'.")
|
||||
} else {
|
||||
// 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,
|
||||
days: period.days
|
||||
}
|
||||
console.log(res);
|
||||
//console.log(res);
|
||||
|
||||
return res
|
||||
})
|
||||
|
||||
Loading…
Reference in New Issue
Block a user