There might be a better way to achieve this, but this is what I got working:
Code:
temp_date = nil
headline = nil
temp_headline = nil
for item in @items
temp_date = item.published
if (temp_date > 1.day.ago)
temp_headline = 'Today'
elsif (temp_date <= 1.day.ago && temp_date > 2.days.ago)
temp_headline = 'Yesterday'
elsif (temp_date <= 2.days.ago && temp_date > 1.week.ago)
temp_headline = Date::DAYNAMES[item.published.wday]
elsif (temp_date <= 1.week.ago && temp_date > 2.weeks.ago)
temp_headline = 'Last Week'
elsif (temp_date <= 2.weeks.ago && temp_date > 3.weeks.ago)
temp_headline = '2 Weeks Ago'
elsif (temp_date <= 3.weeks.ago && temp_date > 4.weeks.ago)
temp_headline = '3 Weeks Ago'
elsif (temp_date <= 1.month.ago && temp_date > 2.months.ago)
temp_headline = 'Last Month'
else
temp_headline = 'Older'
end
if temp_headline != headline
headline = temp_headline
#print out headline here
end
#print out records/object attributes here
end
Bookmarks