From 8f43f7d0c77ac359b6516d09b126bbbb70ee067c Mon Sep 17 00:00:00 2001 From: Tyler Renelle Date: Wed, 11 Jul 2012 15:13:08 -0400 Subject: [PATCH] lastCron: setting as difference between two dates on midnight, currently a bug where it calculates the difference in 24h between two dates --- lib/app/index.js | 13 ++++++++++--- src/app/index.coffee | 13 ++++++++++--- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/lib/app/index.js b/lib/app/index.js index c1b1540459..567bdacd8e 100644 --- a/lib/app/index.js +++ b/lib/app/index.js @@ -512,17 +512,24 @@ ready(function(model) { poormanscron = function() { var DAY, daysPassed, lastCron, today; lastCron = model.get('_user.lastCron'); - lastCron = lastCron ? new Date(lastCron) : new Date(); + if (lastCron) { + lastCron = new Date(model.get('_user.lastCron')); + } else { + lastCron = new Date(); + model.set('_user.lastCron', lastCron); + } + lastCron = new Date("" + (lastCron.getMonth()) + "/" + (lastCron.getDate()) + "/" + (lastCron.getFullYear())); + console.log(lastCron); DAY = 1000 * 60 * 60 * 24; today = new Date(); + today = new Date("" + (today.getMonth()) + "/" + (today.getDate()) + "/" + (today.getFullYear())); daysPassed = Math.floor((today.getTime() - lastCron.getTime()) / DAY); if (daysPassed > 0) { _(daysPassed).times(function() { return endOfDayTally(); }); - lastCron = new Date(); + return model.set('_user.lastCron', today); } - return model.set('_user.lastCron', lastCron); }; poormanscron(); setInterval((function() { diff --git a/src/app/index.coffee b/src/app/index.coffee index 68cdd41397..1ab62b9be5 100644 --- a/src/app/index.coffee +++ b/src/app/index.coffee @@ -386,15 +386,22 @@ ready (model) -> #TODO: remove when cron implemented poormanscron = -> lastCron = model.get('_user.lastCron') - lastCron = if lastCron then (new Date(lastCron)) else new Date() + if lastCron + # need to do date calculation, seems it's stored in db as string + lastCron = new Date(model.get('_user.lastCron')) + else + lastCron = new Date() + model.set('_user.lastCron', lastCron) + lastCron = new Date("#{lastCron.getMonth()}/#{lastCron.getDate()}/#{lastCron.getFullYear()}") # calculate as midnight + console.log lastCron DAY = 1000 * 60 * 60 * 24 today = new Date() + today = new Date("#{today.getMonth()}/#{today.getDate()}/#{today.getFullYear()}") # calculate as midnight daysPassed = Math.floor((today.getTime() - lastCron.getTime()) / DAY) if daysPassed > 0 _(daysPassed).times -> endOfDayTally() - lastCron = new Date() - model.set('_user.lastCron', lastCron) + model.set('_user.lastCron', today) # reset cron poormanscron() # Run once on refresh setInterval (-> # Then run once every hour poormanscron()