From b4e8d1e69a3ccc41f13a918e26ffd3d050c16ec2 Mon Sep 17 00:00:00 2001 From: Tyler Renelle Date: Mon, 28 Jan 2013 14:04:10 -0500 Subject: [PATCH] user.setNull for lastCron right away, to avoid missing lastCrons --- src/app/index.coffee | 5 +++-- src/app/scoring.coffee | 3 +-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/app/index.coffee b/src/app/index.coffee index 9d59ab1499..ef496fd030 100644 --- a/src/app/index.coffee +++ b/src/app/index.coffee @@ -102,7 +102,7 @@ cron = (model) -> # This is an expensive function, only call it on cron lastCron = user.get('lastCron') - return unless !lastCron or (helpers.daysBetween(new Date(), lastCron) > 0) + return unless helpers.daysBetween(+new Date, lastCron) > 0 userObj = user.get() @@ -118,6 +118,7 @@ cron = (model) -> ready (model) -> user = model.at('_user') + user.setNull 'lastCron', +new Date #set cron immediately # Setup model in scoring functions scoring.setModel(model) @@ -236,7 +237,7 @@ ready (model) -> matrix = [['Date', 'Score']] for obj in model.get(historyPath) - date = new Date(obj.date) + date = +new Date(obj.date) readableDate = moment(date).format('MM/DD') matrix.push [ readableDate, obj.value ] data = google.visualization.arrayToDataTable matrix diff --git a/src/app/scoring.coffee b/src/app/scoring.coffee index ae3873005e..9d46f7238f 100644 --- a/src/app/scoring.coffee +++ b/src/app/scoring.coffee @@ -144,7 +144,7 @@ score = (taskId, direction, times, update) -> adjustvalue = if (taskObj.up==false or taskObj.down==false) then false else true calculateDelta(adjustvalue) # Add habit value to habit-history (if different) - historyEntry = { date: new Date(), value: value } if taskObj.value != value + historyEntry = { date: +new Date(), value: value } if taskObj.value != value if (delta > 0) then addPoints() else subtractPoints() model.push "_user.#{taskPath}.history", historyEntry @@ -181,7 +181,6 @@ score = (taskId, direction, times, update) -> ### cron = (userObj) -> today = +new Date - userObj.lastCron ?= today daysPassed = helpers.daysBetween(today, userObj.lastCron) if daysPassed > 0 # Tally each task