Friday, 6 September 2013

Rails daylight savings issue while searching

Rails daylight savings issue while searching

I am searching records in user model. The search attributes from_date,
to_date will be used to searched records in user model based on created_at
column.
User model : (id, name, created_at)
I have the following records in the database.
id, name, created_at
1 jd1 2013-09-04 18:01:57
2 jd2 2013-09-05 19:01:57
3 jd3 2013-09-05 23:01:57
When i am searching, between "2013-09-04"(from_date) and
"2013-09-05"(to_date), only the first
two records are being returned. The last one is not being returned. When i
change the to_date
to "2013-09-06" the record is showing. This is the query i used.
date_range = from_date ... to_date + 1.day
scope :by_date, ->(date_range) {where(created_at: date_range)}
User.by_date(date_range)
What is wrong with the query? I think there is daylight time zone issue
with it.

No comments:

Post a Comment