aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Barnett <noreply@jamesbarnett.xyz>2018-03-31 21:37:02 +0100
committerJames Barnett <noreply@jamesbarnett.xyz>2018-03-31 21:37:02 +0100
commit567bea38fd7524e5e41fc5d09036cf86ad3932cd (patch)
treeb03c8f02699618548837501f4d474c56f532ade2
parentfe70d31cea4869c7f8214dbc1d00fb917816e9a8 (diff)
downloadtplink-energy-monitor-567bea38fd7524e5e41fc5d09036cf86ad3932cd.tar.xz
tplink-energy-monitor-567bea38fd7524e5e41fc5d09036cf86ad3932cd.zip
fillMissingDays now fills the previous month correctly
-rw-r--r--routes/energy-usage.js12
1 files 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);