在 Sequel 中使用 UTC?
我不想将时间存储在我当地的时区,但续集让我变得非常困难。 我可以在将它们放在那里之前将它们设置为 UTC(有点痛苦),但是当我将它们取出时,它会假设它们是本地日期,然后它们都是未来的 8 小时。 这是还没有实施的事情吗? 如果是这样,有什么解决方法吗? 谢谢!
I'd like to not store times in my local timezone, but Sequel is making it really tough on me. I can set them to UTC before I put them in there (a bit of a pain), but then when I take them back out it assumes that they are local dates and then they are all 8 hours in the future. Is this something that hasn't been implemented yet? And if so, are there any workarounds? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这在这一点上有点过时,但我相信自从发布原始答案以来,这里的最佳解决方案已经改变。 如果您设置
sequel 会将所有时间视为UTC,并且不会表现出问题中描述的行为。
欲了解更多信息,请访问 http://sequel.jeremyevans.net/rdoc/classes/Sequel /时区.html
This is a bit outdated at this point but I believe the best solution here has changed since the original answer was posted. If you set
sequel will treat all times as UTC and wont exhibit the behavior described in the question.
Find more info at http://sequel.jeremyevans.net/rdoc/classes/Sequel/Timezones.html
我自己也有一个非常相似的问题。
此信息取自 Sequel RDoc
还要确保您没有将时区信息存储在数据库中。
我使用的是 Postgres,列类型是无时区的时间戳。
这应该会导致显示的日期/时间采用 UTC。 当传入 2009-07-13T03:22:53Z 的日期/时间时,它对我有用,结果显示为 2009-07-13T03:22:53+00:00
Just had a very similar issue myself.
This information has been taken from the Sequel RDoc
Also make sure your not storing the timezone information in your database.
I'm using Postgres and the column type is timestamp without time zone.
This should result in the displayed Date/Time being in UTC. It has worked for me when passing in a Date/Time of 2009-07-13T03:22:53Z the result is displayed as 2009-07-13T03:22:53+00:00
尝试将它们放入 UTC 的最简单方法是覆盖用于返回 UTC 时间文字字符串的数据集类的literal_datetime 和/或literal_time。
以 UTC 格式获取它们取决于您使用的适配器。 例如,postgres适配器调用Sequel.string_to_datetime,它只调用Sequel.datetime_class(默认为Time)上的parse。 如果日期时间列包含时区信息,则一切应该正常。 如果它不包含时区信息,Time.parse 将假定给定的是本地时间。 在这种情况下,您可能需要重写 Sequel.string_to_datetime 以确保它始终返回具有 UTC 偏移量的时间(也许通过调用 Time.parse(s).gmtime )。
The easiest way to try to put them in as UTC is to override literal_datetime and/or literal_time for the dataset class you are using to return a literal string of the UTC time.
Getting them out in UTC depends on the adapter you are using. For example, the postgres adapter calls Sequel.string_to_datetime, which just calls parse on the Sequel.datetime_class (Time by default). If the datetime column includes the timezone information, things should work fine. If it doesn't include timezone information, Time.parse is going to assume it is given a local time. In that case, you may want to override Sequel.string_to_datetime to make sure it always returns the time with the UTC offset (maybe by calling Time.parse(s).gmtime).