The TimeZone class serves as a wrapper around TZInfo::Timezone instances. It allows us to do the following:

  • Limit the set of zones provided by TZInfo to a meaningful subset of 142 zones.

  • Retrieve and display zones with a friendlier name (e.g., “Eastern Time (US & Canada)” instead of “America/New_York”).

  • Lazily load TZInfo::Timezone instances only when they're needed.

  • Create ActiveSupport::TimeWithZone instances via TimeZone's local, parse, atand nowmethods.

If you set config.time_zonein the Rails Initializer, you can access this TimeZone object via

# environment.rb: do |config|
  config.time_zone = "Eastern Time (US & Canada)"
end       # => #<TimeZone:0x514834...>  # => "Eastern Time (US & Canada)"   # => Sun, 18 May 2008 14:30:44 EDT -04:00

The version of TZInfo bundled with Active Support only includes the definitions necessary to support the zones defined by the TimeZone class. If you need to use zones that aren't defined by TimeZone, you'll need to install the TZInfo gem (if a recent version of the gem is installed locally, this will be used instead of the bundled version.)

Required Files