DataMapper query - last year, last month etc

I use sinatra web framework and DataMapper.

I have code:

@wdata = Data.all(:date => ((DateTime.now - @interval.to_i)..DateTime.now))

When I want Data from last 24 hours I use @interval = 1, last 7 days @interval = 7.

How I should get data from e.g. last month or last year? Month can have 31, 30, 28 or 29 days I would like to distinguish this. I would e.g. get data from june last year, last two months, etc.

I searched in web for some tutorial, but I found only for ActiveRecord. :(

Answers


Perhaps there is more elegant solution, but you can do such ranges manually

d = DateTime.today
p = d.prev_month
py = d.prev_year
last_month = Data.all(:date => (DateTime.new(p.year, p.month)..DateTime.new(d.year, d.month))
last_year = Data.all(:date => (DateTime.new(py.year)..DateTime.new(d.year))

Need Your Help

Make a custom ListView with List<String> in Android

java android listview android-custom-view

I have tried this , but it doesn´t work, I want to make that each one of the list(origen, destino,dias) were each one of the columns of my custom ListView.

Image Change with Mouse Hover

html css image hyperlink hover

I have some links to my facebook and twitter, these links are images. I want these links to turn lighter when I hover over them. I was thinking I could do this by making two images and making the i...