From 567bea38fd7524e5e41fc5d09036cf86ad3932cd Mon Sep 17 00:00:00 2001 From: James Barnett Date: Sat, 31 Mar 2018 21:37:02 +0100 Subject: fillMissingDays now fills the previous month correctly --- routes/energy-usage.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/routes/energy-usage.js b/routes/energy-usage.js index 411c0b6..740e29e 100644 --- a/routes/energy-usage.js +++ b/routes/energy-usage.js @@ -95,8 +95,16 @@ router.get('/:deviceId/month-stats', function(req, res, next) { function fillMissingDays(sparseDayStats, statsMoment) { let denseDayStats = []; - // Fill in any missing days - let totalDays = statsMoment.date(); + let totalDays; + // If these stats are for the current month, fill up to the current day of the month + // Otherwise fill the whole month + if(moment().month() === statsMoment.month()) { + totalDays = statsMoment.date(); + } + else { + totalDays = statsMoment.daysInMonth(); + } + Array.from({length: totalDays}, (x,i) => i + 1).forEach(d => { let stat = sparseDayStats.day_list.find(i => i.day === d); -- cgit v1.2.3