Rails 忽略夏令时 [英] Rails ignore daylight savings time

查看:38
本文介绍了Rails 忽略夏令时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于夏令时,我无法理解 Rails 的时区支持.

I am having trouble understanding Rails' time zone support when it comes to daylight savings time.

我以UTC存储所有数据库时间.存储用户时区,以便它们直接映射回 ActiveSupport::TimeZone 值(即 中部时间(美国和加拿大)).

I am storing all database times in UTC. User timezones are stored so that they map directly back to ActiveSupport::TimeZone values (i.e. Central Time (US & Canada)).

我想完全忽略夏令时.如果活动在 5:30pm 开始,无论夏令时是否生效,它总是在 5:30pm 开始.

I want to completely ignore daylight savings time. If an event starts at 5:30pm, it always starts at 5:30pm whether daylight savings time is in effect or not.

考虑到所有时间都是统一存储的,是否有可能检索数据库时间并在本地显示它们以便完全忽略夏令时?如果忽略夏令时,我会遇到什么问题吗?

Is it possible, considering all times are stored uniformly, to retrieve database times and display them locally so that daylight savings is completely ignored? Are there any problems I am going to run into ignoring daylight savings?

推荐答案

我的意思不是学究气,但是...

I don't mean to sound pedantic, but...

我想完全忽略夏令时.

好吧,那你就靠自己了.尽管我们抱有最大的希望和愿望,但现实世界的大部分地区都使用夏令时.您可以在此处获得快速入门.

Well, you will be on your own then. Despite our best hopes and wishes, much of the real world uses daylight saving time. You can get a quick primer here.

如果活动在下午 5:30 开始,无论夏令时是否生效,它始终在下午 5:30 开始.

If an event starts at 5:30pm, it always starts at 5:30pm whether daylight savings time is in effect or not.

5:30 给谁?如果您说的是 UTC 时间 5:30,那么当然可以.但是,如果您说的是美国中部时间 5:30,则必须考虑 DST.否则,人们会在他们认为是 5:30 而你认为是 6:30 的时候出现在你的活动中.

5:30 for who? If you're saying 5:30 UTC, then sure. But if you're saying 5:30 in US Central Time, then you have to take DST into account. Otherwise, half of the year people will show up at your event at what they think is 5:30 and you think is 6:30.

考虑到所有时间都是统一存储的,是否有可能检索数据库时间并在本地显示它们以便完全忽略夏令时?

Is it possible, considering all times are stored uniformly, to retrieve database times and display them locally so that daylight savings is completely ignored?

您以 UTC 格式存储时间,这很好.当您在本地显示它们时,您应该不要忽略 DST.

You're storing the times in UTC, which is good. When you display them locally, you should not ignore DST.

如果忽略夏令时,我会遇到什么问题吗?

Are there any problems I am going to run into ignoring daylight savings?

是的,人们通常不理解这一点.人们普遍认为,如果您指的是当地时间,则是指他们 的当地时间.如果您在该计算中不包括夏令时,那么您将对所讨论的时间产生分歧.

Yes, people don't commonly understand this. It's generally expected that if you refer to a local time, that you mean a time that is local for them. If you don't include DST in that calculation, then you will have a disagreement about what time you are talking about.

另外一个忠告,您可能需要考虑使用 TZInfo gem 而不是 ActiveSupport::时区.然后,您将使用 IANA 标识符(例如 America/Chicago)存储时区选择.这些在 Rails 之外是可识别的.

Another word of advice, you might want to consider using the TZInfo gem instead of ActiveSupport::TimeZone. Then you would store time zone selection using the IANA identifiers such as America/Chicago. These are recognizable outside of Rails.

出于某种无法解释的原因,ActiveSupport 人员认为他们应该将时区限制为他们认为有意义"的 146 个值.但是他们没有解释他们的过程,而且他们似乎并不处于维护状态.我问过为什么,但没有得到太多详细回复.

For some unexplained reason, the ActiveSupport folks thought they should limit time zones to the 146 values they felt were "meaningful". But they didn't explain their process, and they don't seem to be on top of maintenance. I've asked why, but haven't gotten much of a detailed response.

您可能还希望查看时区标签维基.

这篇关于Rails 忽略夏令时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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