Searchlogic无法针对日期时间条件正确转换时间 [英] Searchlogic doesn't convert the time properly for datetime conditions

查看:115
本文介绍了Searchlogic无法针对日期时间条件正确转换时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Searchlogic的作者说,它被委派给了A :: R转换器,但至少在我们的案例中,这没有涵盖通常的情况.当地时间被解释为" UTC,因此被移动了一个小时(CET).

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).

我该怎么做呢?

我将当前的解决方法作为答案,希望对您有所帮助!

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

推荐答案

我们已将以下方法添加到应用程序控制器中:

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

然后在创建searchlogic对象之前,我们先对params哈希进行预处理":

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 :)!

我们的environment.rb:

our environment.rb:

  config.time_zone = 'Bern'
  config.active_record.default_timezone = :utc

这篇关于Searchlogic无法针对日期时间条件正确转换时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆