diff --git a/lib/app/helpers.js b/lib/app/helpers.js index 9b81281493..9a40cb4e67 100644 --- a/lib/app/helpers.js +++ b/lib/app/helpers.js @@ -5,7 +5,7 @@ module.exports.daysBetween = function(a, b) { DAY = 1000 * 60 * 60 * 24; a = new Date((new Date(a)).toDateString()); b = new Date((new Date(b)).toDateString()); - return Math.floor((a.getTime() - b.getTime()) / DAY); + return Math.abs(Math.floor((a.getTime() - b.getTime()) / DAY)); }; module.exports.viewHelpers = function(view) { diff --git a/lib/app/index.js b/lib/app/index.js index 898cfecf03..2cba095196 100644 --- a/lib/app/index.js +++ b/lib/app/index.js @@ -290,12 +290,11 @@ ready(function(model) { return model.set('_items.weapon', content.items.weapon[1]); }; exports.poormanscron = poormanscron = function() { - var DAY, daysPassed, lastCron, n, today, _k, _results; - model.setNull('_user.lastCron', new Date()); - 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); + var daysPassed, lastCron, n, today, _k, _results; + today = new Date(); + model.setNull('_user.lastCron', today); + lastCron = model.get('_user.lastCron'); + daysPassed = helpers.daysBetween(lastCron, today); if (daysPassed > 0) { model.set('_user.lastCron', today); _results = []; diff --git a/src/app/helpers.coffee b/src/app/helpers.coffee index 4d60728915..3be8964ec7 100644 --- a/src/app/helpers.coffee +++ b/src/app/helpers.coffee @@ -4,7 +4,7 @@ module.exports.daysBetween = (a, b) -> # calculate as midnight a = new Date( (new Date(a)).toDateString() ) b = new Date( (new Date(b)).toDateString() ) - return Math.floor((a.getTime() - b.getTime()) / DAY) + return Math.abs(Math.floor((a.getTime() - b.getTime()) / DAY)) module.exports.viewHelpers = (view) -> view.fn 'taskClasses', (type, completed, value) -> diff --git a/src/app/index.coffee b/src/app/index.coffee index 0b989baa95..f196e1fd56 100644 --- a/src/app/index.coffee +++ b/src/app/index.coffee @@ -237,11 +237,10 @@ 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 - DAY = 1000 * 60 * 60 * 24 - daysPassed = Math.floor((today.getTime() - lastCron.getTime()) / DAY) + today = new Date() + model.setNull('_user.lastCron', today) + lastCron = model.get('_user.lastCron') + daysPassed = helpers.daysBetween(lastCron, today) if daysPassed > 0 model.set('_user.lastCron', today) # reset cron for n in [1..daysPassed]