Searchlogic 无法根据日期时间条件正确转换时间

发布于 2024-08-21 20:42:01 字数 151 浏览 5 评论 0原文

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

How can I do that properly?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

巴黎盛开的樱花 2024-08-28 20:42:01

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

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

然后在创建 searchlogic 对象之前,我们“预处理”参数哈希:

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

非常感谢任何更清晰、更好、更好的解决方案/想法:)!

我们的环境.rb:

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文