Fixed issue where incorrect time type passed in for shouldDo’s ‘day’ argument (should be a Date, sometimes Moment is passed in). Fixed incorrect comparison between Moment and Date.

This commit is contained in:
Allen Pan 2015-05-15 20:21:43 -07:00
parent e7cd3ff533
commit d1805f9181
2 changed files with 4 additions and 4 deletions

View file

@ -86,7 +86,7 @@ api.shouldDo = (day, dailyTask, options = {}) ->
dayOfWeek = api.startOfDay(_.defaults {now:day}, o).day()
# check if event is in the future
hasStartedCheck = moment(day).isAfter(dailyTask.startDate) || moment(day).isSame(dailyTask.startDate)
hasStartedCheck = day >= dailyTask.startDate
if dailyTask.frequency == 'daily'
daysSinceTaskStart = api.numDaysApart(day, dailyTask.startDate, o)
@ -1547,7 +1547,7 @@ api.wrap = (user, main=true) ->
{completed, repeat} = daily
thatDay = moment(now).subtract({days: 1})
if api.shouldDo(thatDay, repeat, user.preferences) || completed
if api.shouldDo(thatDay.toDate(), daily, user.preferences) || completed
_.each daily.checklist, ((box)->box.completed=false;true)
daily.completed = false
return
@ -1574,7 +1574,7 @@ api.wrap = (user, main=true) ->
scheduleMisses = 0
_.times daysMissed, (n) ->
thatDay = moment(now).subtract({days: n + 1})
if api.shouldDo(thatDay, task, user.preferences)
if api.shouldDo(thatDay.toDate(), task, user.preferences)
scheduleMisses++
if user.stats.buffs.stealth
user.stats.buffs.stealth--

View file

@ -793,7 +793,7 @@ describe 'Cron', ->
before.dailys[0].streak = after.dailys[0].streak = 10
before.dailys[0].completed = after.dailys[0].completed = true if options.checked
if options.shouldDo
expect(shared.shouldDo(now, options.repeat, {timezoneOffset, dayStart:options.dayStart, now})).to.be.ok()
expect(shared.shouldDo(now.toDate(), options.repeat, {timezoneOffset, dayStart:options.dayStart, now})).to.be.ok()
after.fns.cron {now}
before.stats.mp=after.stats.mp #FIXME
switch options.expect