jeudi 28 avril 2016

How to detect if dates are consecutive in Rails?

I'm looking to check for consecutive dates and display them differently if they are consecutive.

I'm working with Garage Sales that have multiple dates per sale. I'd like to then cycle through each date, and group any consecutive dates to display as a group: Ex: Apr 28 - Apr 30

I also need to account for non-consecutive dates: Ex: Apr 15, Apr 28 - 30

Additionally, weekly dates need to be recognized as non-consecutive (so basically avoid step checks): Ex: Apr 16, Apr 23, Apr 30


So far, I'm taking each date that hasn't passed & ordering them properly.

garage_sale_dates.where("date > ?",Time.now).order(:date)

Thanks for any help! Let me know if any other info is needed.

Aucun commentaire:

Enregistrer un commentaire