意外的Time.zone.now结果

时间:2015-08-12 13:13:40

标签: ruby-on-rails ruby timezone

所以,拥有开发和生产服务器。

development.rb

  config.cache_classes = false
  config.whiny_nils = true

  config.consider_all_requests_local       = true
  config.action_controller.perform_caching = false

  config.action_mailer.raise_delivery_errors = false
  config.active_support.deprecation = :log
  config.action_dispatch.best_standards_support = :builtin

production.rb

  config.cache_classes = true

  config.consider_all_requests_local       = false
  config.action_controller.perform_caching = true

  config.action_dispatch.x_sendfile_header = "X-Sendfile"

  config.cache_store = :redis_store, 'redis://localhost:6379/0/cache', { expires_in: 90.minutes, namespace: 'production' }
  config.serve_static_assets = false

  config.i18n.fallbacks = true

  config.active_support.deprecation = :notify

application.rb

require File.expand_path('../boot', __FILE__)
require 'rails/all'

Bundler.require(:default, Rails.env) if defined?(Bundler)
Dotenv::Railtie.load

require "sprockets/railtie"

module S2yd
  class Application < Rails::Application
    config.autoload_paths += %W( #{config.root}/lib #{config.root}/app/forms #{config.root}/app/decorators )
    config.time_zone = 'Central Time (US & Canada)'
    config.encoding = "utf-8"
    config.filter_parameters += [:password, :active_merchant_billing_credit_card, :payment_cc_number, :payment_cc_verification_value, 'credit_card[number]', 'credit_card[verification_value]']
    config.assets.enabled = true
    config.assets.paths << File.join(Rails.root, 'vendor', 'assets', 'javascripts')
    config.assets.paths << File.join(Rails.root, 'vendor', 'assets', 'stylesheets')
    config.assets.precompile += %w( .svg .eot .woff .ttf )
    config.assets.precompile += %w(
      font/*.*
      img/*.*
    )
    config.assets.initialize_on_precompile = true
    # Version of your assets, change this if you want to expire all your assets
    config.assets.version = '1.2'
  end
end

在开发机器上:

dev@dev:~/www/mxad-mr.-delivery$ date
Wed Aug 12 09:02:41 EDT 2015

在prod机器上:

deploy@production-web:~$ date
Wed Aug 12 12:50:13 UTC 2015

在开发机器上的开发rails控制台上:

1.9.3-p484 :010 > Time.zone.now
 => Wed, 12 Aug 2015 06:07:41 PDT -07:00 
1.9.3-p484 :015 > Time.now
 => 2015-08-12 09:29:46 -0400
1.9.3-p484 :016 > Time.now.zone
 => "EDT

在生产机器上的生产轨道控制台上:

irb(main):018:0>  Time.zone.now
=> Wed, 12 Aug 2015 08:08:06 CDT -05:00
irb(main):032:0> Time.now
=> 2015-08-12 13:29:44 +0000
irb(main):033:0> Time.now.zone
=> "UTC"

我预计 Time.zone.now 会在application.rb中设置time_zone当前时间。但事实并非如此。所以,应该是prod&amp; dev机器轨道控制台在同一时区中部时间(美国和加拿大)(参见application.rb)。
为什么不呢?

0 个答案:

没有答案