Rails arel table query with Date and Time -


i having problems query because midnight conversion not working expected.

time = date.today.midnight #=> mon, 15 jul 2013 00:00:00 brt -03:00  time.class #=> activesupport::timewithzone  condition = task.arel_table[:scheduled_to].gt(time)  condition.to_sql #=> "`tasks`.`scheduled_to` > '2013-07-15 03:00:00'" 

i expecting generated sql be

`tasks`.`scheduled_to` > '2013-07-15 00:00:00'" 

my time zone gmt -3. if change time zone matches gmt -5 generated sql is

condition.to_sql #=> "`tasks`.`scheduled_to` > '2013-07-15 05:00:00'" 
  • rails 4.0.0
  • ruby 2.0.0p247

is there way ignore timezone query behaves expected?

timezones relative utc (0000), gotta remove date.

datetime.now.midnight.utc #=> '2013-08-23 03:00:00 +0000' 

now, rid compensated hours.

datetime.now.midnight.utc.change({:hour => 0, :min => 0}) #=> '2013-08-23 00:00:00 +0000' 

not sure if there cleaner way it, worked me (ruby 1.9.3p385).


Comments