views:

110

answers:

2

The author of Searchlogic says that it is delegated to A::R converter, but at least in our case this didn't cover the usual cases. Local time was 'interpreted' as UTC and therefore was moved by one hour (CET).

How can I do that properly?

I add our current workaround as an answer, hopefully it helps somebody!

A: 

We've added the following method to the application controller:

  protected
  def parse_datetime_fields(hash, key)
    value = hash[key]
    return unless value
    hash[key] = Time.zone.parse(value)
  end

And then before creating the searchlogic object we 'preprocess' the params hash:

if params[:search]
  parse_datetime_fields(params[:search], :begin_greater_than)
  parse_datetime_fields(params[:search], :begin_less_than)
end

@search = Record.search(params[:search])

Any clearer better and nicer solutions/ideas are very appreciated :)!

our environment.rb:

  config.time_zone = 'Bern'
  config.active_record.default_timezone = :utc
reto
I accept this answer for now, if there are better solutions I will update it.
reto
A: 

I had the same problem. Datetime search filters on a report were bumping ahead by X hours every time I ran the search, where X is the timezone offset of the current user. Your solution worked, Thanks.