mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-08-01 11:40:25 +00:00
DRY daysPassed with helpers.daysBetween
This commit is contained in:
parent
39088570ce
commit
0f013d2ef3
4 changed files with 11 additions and 13 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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 = [];
|
||||
|
|
|
|||
|
|
@ -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) ->
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
|
|
|
|||
Loading…
Reference in a new issue