I\'m creating a habit tracking app.
When a User creates a habit he will put in its :date_started
and which days he is :committed
to doing t
I believe your only problem is that you're storing the day names in lowercase in the committed
field, and then trying to match them with Date::DAYNAMES
, which has them in title case. Otherwise, the logic seems sound.
This should work:
committed_wdays = committed.map { |day| Date::DAYNAMES.index(day.titleize) }
n_days = ((date_started.to_date)..Date.today).count { |date| committed_wdays.include? date.wday }