From 8208532601926cd75b00cd1506b3e6dca4e0459b Mon Sep 17 00:00:00 2001 From: Eddy Harrington Date: Thu, 1 Apr 2021 13:18:51 -0700 Subject: [PATCH] Improve date format on dashboard's weekly chart --- static/js/dashboard.js | 2 +- tendie_dashboard.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/static/js/dashboard.js b/static/js/dashboard.js index f33c473..37b79e6 100644 --- a/static/js/dashboard.js +++ b/static/js/dashboard.js @@ -86,7 +86,7 @@ function loadWeeklySpendingCharts(weeklySpending) { let spendingChart = new Chart(chartElement, { type: 'line', data: { - labels: [weeklySpending[0].startOfWeek.slice(5) + " - " + weeklySpending[0].endOfWeek.slice(5), weeklySpending[1].startOfWeek.slice(5) + " - " + weeklySpending[1].endOfWeek.slice(5), weeklySpending[2].startOfWeek.slice(5) + " - " + weeklySpending[2].endOfWeek.slice(5), weeklySpending[3].startOfWeek.slice(5) + " - " + weeklySpending[3].endOfWeek.slice(5)], + labels: [weeklySpending[0].startOfWeek.slice(0, 6) + " - " + weeklySpending[0].endOfWeek.slice(0, 6), weeklySpending[1].startOfWeek.slice(0, 6) + " - " + weeklySpending[1].endOfWeek.slice(0, 6), weeklySpending[2].startOfWeek.slice(0, 6) + " - " + weeklySpending[2].endOfWeek.slice(0, 6), weeklySpending[3].startOfWeek.slice(0, 6) + " - " + weeklySpending[3].endOfWeek.slice(0, 6)], datasets: [{ label: 'Total $ Spent', data: [(Math.round(weeklySpending[0].amount * 100) / 100), (Math.round(weeklySpending[1].amount * 100) / 100), (Math.round(weeklySpending[2].amount * 100) / 100), (Math.round(weeklySpending[3].amount * 100) / 100)], diff --git a/tendie_dashboard.py b/tendie_dashboard.py index 89582b8..8a2b6de 100644 --- a/tendie_dashboard.py +++ b/tendie_dashboard.py @@ -122,11 +122,11 @@ def getWeeklySpending(weekNames, userID): # Loop through each week and store the name/amount in a dict for name in weekNames: - week["endOfWeek"] = str(name["endofweek"]) - week["startOfWeek"] = str(name["startofweek"]) + week["endOfWeek"] = name['endofweek'].strftime('%b %d') + week["startOfWeek"] = name['startofweek'].strftime('%b %d') results = db.execute( "SELECT SUM(amount) AS amount FROM expenses WHERE user_id = :usersID AND date_part('year', date(expensedate)) = date_part('year', date(:weekName)) AND date_part('week', date(expensedate)) = date_part('week',date(:weekName))", - {"usersID": userID, "weekName": week["endOfWeek"]}).fetchall() + {"usersID": userID, "weekName": str(name["endofweek"])}).fetchall() weekSpending = convertSQLToDict(results) # Set the amount to 0 if there are no expenses for a given week