UTC dates for date param so modlog doesnt get broken by timezones

merge-requests/208/head
fatchan 5 years ago
parent d38cd55b1d
commit 29e78c2e2b
  1. 6
      helpers/paramconverter.js
  2. 8
      models/pages/modlog.js

@ -104,10 +104,10 @@ module.exports = (req, res, next) => {
} }
//moglog date //moglog date
if (req.params.date) { if (req.params.date) {
const dateString = req.params.date.replace(/-/g, '/'); const [ month, day, year ] = req.params.date.split('-');
const date = new Date(dateString); const date = new Date(Date.UTC(year, month, day, 0, 0, 0, 0));
if (date !== 'Invalid Date') { if (date !== 'Invalid Date') {
res.locals.date = date; res.locals.date = { month, day, year, date };
} }
} }

@ -9,10 +9,10 @@ module.exports = async (req, res, next) => {
return next(); return next();
} }
const startDate = new Date(res.locals.date); const startDate = res.locals.date.date;
const endDate = new Date(startDate.valueOf()); const { year, month, day } = res.locals.date;
startDate.setHours(0,0,0,0); const endDate = new Date(Date.UTC(year, month, day, 23, 59, 59, 999));
endDate.setHours(23,59,59,999);
let html; let html;
try { try {
const logs = await Modlogs.findBetweenDate(res.locals.board, startDate, endDate); const logs = await Modlogs.findBetweenDate(res.locals.board, startDate, endDate);

Loading…
Cancel
Save