Agile Web Development

Build it. Launch it. Love it.

TZInfo Timezone

This plugin installs a replacement for the TimeZone class. The replacement uses the TZInfo library (http://tzinfo.rubyforge.org) to do the time zone conversions, and thus takes into account daylight saving, for free.

It is not a 100%-compatible replacement, however. If you use TimeZone#unadjust anywhere, you'll need to replace those calls, possibly with #local_to_utc. Also, the #adjust method is deprecated--it is better (and easier to read) if you use the #utc_to_local method instead.

Note that you will need to have the tzinfo library installed separately--it is not bundled with this plugin. You can easily install tzinfo as a gem:

gem install tzinfo

Vitals

Repository http://dev.rubyonrails.org/svn/rails/plugins/tzinfo_timezone/
License Rails' (MIT)
Rating (26 votes)
Created 18 May 2006

Comments

  • Avatar
    15 March 2007

    This plugin really improves life for i18n apps. But, many developers have been using TZInfo "manually" for some time and have invested in attributes (on User or Account, etc.) to track the TZInfo timezone by name. Furthermore, some find the TZInfo zone names to be more intuitive.

    It would be great if this plugin would accept the TZInfo timezone names as well. I offer my patched version. See http://cho.hapgoods.com/wordpress/?p=140

  • Avatar
    Andrew Kaspick
    28 June 2007

    Does anybody ever get this? I can't seem to find any reason why this happens, but it doesn't occur all the time.

    can't modify frozen object
    #{RAILS_ROOT}/vendor/plugins/tzinfo_timezone/lib/tzinfo_timezone.rb:215:in `tzinfo'
    #{RAILS_ROOT}/vendor/plugins/tzinfo_timezone/lib/tzinfo_timezone.rb:193:in `local_to_utc'

  • Avatar
    24 November 2007

    You can also check our extension of TZInfo, which lets you do the following in models for auto conversion:

    hastimezone :fields => [:startdatetime, :end_datetime]

    http://hackd.wordpress.com/2007/11/23/sexy-time-zones-in-ruby-on-rails-with-timezone_fu/

  • Dave
    24 January 2008

    Andrew: It may be due to you using composedof on the timezone. Composedof seems to freeze

    Try changing the tzinfo of tzinfo_timezone.rb method to

    def tzinfo MAPPING[@name] = TZInfo::Timezone.get(MAPPING[@name]) if String === MAPPING[@name] return MAPPING[@name] end

    thus avoiding the frozen @tzinfo.

    Used it at own risk, but works for me at least.

Add a comment