问题
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!
回答1:
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
来源:https://stackoverflow.com/questions/2280980/searchlogic-doesnt-convert-the-time-properly-for-datetime-conditions