I'm having trouble with the first loop. The second one successfully fills the @res[] array whereas the first one doesn't.
@res = {}
[:disc, :wpmot, :df, :ptsi, :eq].each do |t|
tool = Tool.find_by(name: t)
p (to - from)
@res[t] = tool.certifieds.where(date: to - from)
end
.
.
.
@res = {}
[:disc, :wpmot, :df, :ptsi, :eq].each do |t|
tool = Tool.find_by(name: t)
p (Date.today - 1.months..Date.today)
@res[t] = tool.certifieds.where(date: Date.today - 1.months..Date.today)
end
to
and from
are defined as such:
from = Date.new(start_year, start_month, start_day)
to = Date.new(end_year, end_month, end_day)
I then printed both values to see if they correspond but they didn't.
p (Date.today - 1.months..Date.today)
gave me 'Mon, 11 Nov 2019..Wed, 11 Dec 2019'
whereas p (to - from)
gave me '(1/1)'
(sort of ratio between both dates). So I do understand that the first loop isn't working because the Date
objects aren't correct. What is it that I'm doing wrong ?
Cheers.