some bug-fixes on shouldDo() for today-check

This commit is contained in:
Tyler Renelle
2013-05-25 18:26:07 +01:00
parent 12ef6edf8d
commit 51a80b6626
3 changed files with 27 additions and 10 deletions
+1 -1
View File
@@ -356,7 +356,7 @@ obj.cron = (user, options={}) ->
scheduleMisses = 0
_.times daysMissed, (n) ->
thatDay = moment(now).subtract('days', n + 1)
scheduleMisses++ if helpers.shouldDo(thatDay, repeat, obj.preferences?.dayStart) is true
scheduleMisses++ if helpers.shouldDo(thatDay, repeat, {dayStart:obj.preferences?.dayStart})
obj.score(user, task, 'down', {times:scheduleMisses, cron:true, paths:paths}) if scheduleMisses > 0
switch type
+3 -3
View File
@@ -18,9 +18,9 @@ daysBetween = (yesterday, now, dayStart) -> Math.abs sod(yesterday, dayStart).di
###
Should the user do this taks on this date, given the task's repeat options and user.preferences.dayStart?
###
shouldDo = (day, repeat, dayStart=0) ->
shouldDo = (day, repeat, options={}) ->
return false unless repeat
now = +new Date
[dayStart,now] = [options.dayStart||0, options.now||+new Date]
selected = repeat[dayMapping[sod(day, dayStart).day()]]
return selected unless moment(day).isSame(now,'d')
if dayStart <= moment(now).hour() # we're past the dayStart mark, is it due today?
@@ -245,7 +245,7 @@ module.exports =
# show as completed if completed (naturally) or not required for today
if type in ['todo', 'daily']
if completed or (type is 'daily' and !shouldDo(+new Date, task.repeat, dayStart))
if completed or (type is 'daily' and !shouldDo(+new Date, task.repeat, {dayStart}))
classes += " completed"
else
classes += " uncompleted"