生产和开发之间奇怪的时间不一致 [英] Weird time inconsistencies between production and development
问题描述
heroku db:pull
,所以数据库应该是相同的) 制作(Heroku)
>> Annotation.last.id
=> 2028
>> Annotation.last.created_at
=> Sat,12 Sep 2009 06:51:33 UTC +00:00
>> Time.zone
=> #< ActiveSupport :: TimeZone:0x2b4972a4e2f0 @tzinfo =#< TZInfo :: DataTimezone:Etc / UTC> ;, @ utc_offset = 0,@ name =UTC>
>> Time.now.zone
=> PDT
开发(我的Macbook Pro)
>> Annotation.last.id
=> 2028
>> Annotation.last.created_at
=>周六,2009年9月12日09:51:33 UTC +00:00
>> Time.zone
=> #< ActiveSupport :: TimeZone:0x23c92c0 @tzinfo =#< TZInfo :: DataTimezone:Etc / UTC> ;, @ utc_offset = 0,@ name =UTC>
>> Time.now.zone
=> EDT
由于 created_at
次数不同到3小时后,我认为这与EDT和PDT之间的3小时差异有关,但我不确定发生了什么。
编辑:以下是原始数据的样子:
sqlite>从id = 2028的注释中选择created_at;
2009-09-12T09:51:33-04:00
在Heroku和开发机器之间移动数据库时,看起来这是一个问题。直接运行SQL查询给了我:
本地:{created_at=>2009-10-30 22: 34:55.919586}
远程:{created_at=>2009-10-31 01:34:55.919586}
同样的问题,正好是三个小时的班次。通过Tap的源头,Gem heroku使用数据库同步,并没有提供任何可能出错的线索。我已经打开了一个heroku支持票,我会用我发现的内容更新这篇文章。
更新:
Heroku的Ricardo和Morten回答。在命令行上指定TZ,如下所示:
TZ = America / Los_Angeles heroku db:pull
For some reason times are appearing differently in development (my local Mac) and production (Heroku). Take a look: (Just prior to doing this I did a heroku db:pull
, so the databases should be identical)
Production (Heroku)
>> Annotation.last.id
=> 2028
>> Annotation.last.created_at
=> Sat, 12 Sep 2009 06:51:33 UTC +00:00
>> Time.zone
=> #<ActiveSupport::TimeZone:0x2b4972a4e2f0 @tzinfo=#<TZInfo::DataTimezone: Etc/UTC>, @utc_offset=0, @name="UTC">
>> Time.now.zone
=> "PDT"
Development (my Macbook Pro)
>> Annotation.last.id
=> 2028
>> Annotation.last.created_at
=> Sat, 12 Sep 2009 09:51:33 UTC +00:00
>> Time.zone
=> #<ActiveSupport::TimeZone:0x23c92c0 @tzinfo=#<TZInfo::DataTimezone: Etc/UTC>, @utc_offset=0, @name="UTC">
>> Time.now.zone
=> "EDT"
Since the created_at
times differ by 3 hours, I assume this is related to the 3 hour difference between EDT and PDT, but I'm not sure what's going on.
EDIT: Here's what the raw data looks like:
sqlite> Select created_at from annotations where id = 2028;
2009-09-12T09:51:33-04:00
It looks like this is a problem when moving databases between Heroku and your development machine. Running the SQL query directly gives me this:
Local: {"created_at"=>"2009-10-30 22:34:55.919586"}
Remote: {"created_at"=>"2009-10-31 01:34:55.919586"}
Same problem, exactly a three hour shift. Looking through the source for Taps, the Gem heroku uses for DB sync, does not provide any clues into what could be going wrong here. I've opened a heroku support ticket, and I'll update this post with what I find.
UPDATE: Ricardo and Morten from Heroku replied. Specify the TZ on the command line like so:
TZ=America/Los_Angeles heroku db:pull
这篇关于生产和开发之间奇怪的时间不一致的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!