mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 15:48:04 +01:00
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:
@@ -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() {
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user