lastCron: setting as difference between two dates on midnight,

currently a bug where it calculates the difference in 24h between two
dates
This commit is contained in:
Tyler Renelle
2012-07-11 15:13:08 -04:00
parent 526f32b6c2
commit 8f43f7d0c7
2 changed files with 20 additions and 6 deletions

View File

@@ -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() {

View File

@@ -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()