From 3a155fb3066e60772d3a2e0f48bf09ac0cad1ac3 Mon Sep 17 00:00:00 2001 From: Tyler Renelle Date: Fri, 13 Jul 2012 09:43:53 -0500 Subject: [PATCH] Trying (new Date) instead of new Date() due to multiple crons on 1 day bug --- lib/app/index.js | 11 ++++++++--- src/app/index.coffee | 5 +++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/app/index.js b/lib/app/index.js index 78f2936da3..d87ece74db 100644 --- a/lib/app/index.js +++ b/lib/app/index.js @@ -518,15 +518,20 @@ ready(function(model) { exports.poormanscron = poormanscron = function() { var DAY, daysPassed, lastCron, today; model.setNull('_user.lastCron', new Date()); - lastCron = new Date(new Date(model.get('_user.lastCron')).toDateString()); - today = new Date(new Date().toDateString()); + lastCron = new Date((new Date(model.get('_user.lastCron'))).toDateString()); + today = new Date((new Date).toDateString()); DAY = 1000 * 60 * 60 * 24; daysPassed = Math.floor((today.getTime() - lastCron.getTime()) / DAY); if (daysPassed > 0) { _(daysPassed).times(function() { return endOfDayTally(); }); - return model.set('_user.lastCron', today); + model.set('_user.lastCron', today); + return console.log({ + today: today, + lastCron: lastCron, + daysPassed: daysPassed + }, 'cron debugging'); } }; poormanscron(); diff --git a/src/app/index.coffee b/src/app/index.coffee index 7548df8f9b..60dd5f6d43 100644 --- a/src/app/index.coffee +++ b/src/app/index.coffee @@ -398,14 +398,15 @@ ready (model) -> #TODO: remove when cron implemented exports.poormanscron = poormanscron = -> model.setNull('_user.lastCron', new Date()) - lastCron = new Date(new Date(model.get('_user.lastCron')).toDateString()) # calculate as midnight - today = new Date(new Date().toDateString()) # calculate as midnight + lastCron = new Date( (new Date(model.get('_user.lastCron'))).toDateString() ) # calculate as midnight + today = new Date((new Date).toDateString()) # calculate as midnight DAY = 1000 * 60 * 60 * 24 daysPassed = Math.floor((today.getTime() - lastCron.getTime()) / DAY) if daysPassed > 0 _(daysPassed).times -> endOfDayTally() model.set('_user.lastCron', today) # reset cron + console.log {today: today, lastCron: lastCron, daysPassed: daysPassed}, 'cron debugging' poormanscron() # Run once on refresh setInterval (-> # Then run once every hour poormanscron()