cron: better solution to testing "due today" for tasks with repeat

options, and user with custom dayStart. Still not sure if this is the
ideal solution, but addresses #963
This commit is contained in:
Tyler Renelle
2013-05-14 19:01:05 +01:00
parent 3ae295c9a3
commit 950be4daf2
+6 -3
View File
@@ -18,9 +18,12 @@ shouldDo = (day, repeat, dayStart=0) ->
return false unless repeat
now = +new Date
selected = repeat[dayMapping[sod(day, dayStart).day()]]
if moment(day).isSame(now,'d')
return selected and dayStart <= moment(now).hour()
return selected
return selected unless moment(day).isSame(now,'d')
if dayStart <= moment(now).hour() # we're past the dayStart mark, is it due today?
return selected
else # we're not past dayStart mark, check if it was due "yesterday"
yesterday = moment(now).subtract(1,'d').day()
return repeat[dayMapping[yesterday]]
# http://stackoverflow.com/questions/2532218/pick-random-property-from-a-javascript-object
# obj: object