Troubleshooting "can't modify frozen object" in tzinfo_timezone

Hi. Off and on I get a "can't modify frozen object" when working with the tzinfo_timezone plugin. I've added some debugging in the code to try and track down what goes wrong:

  def tzinfo     RAILS_DEFAULT_LOGGER.debug("TZINFO STATE '#{@tzinfo}' class #{@tzinfo.class} frozen? #{@tzinfo.frozen?}")     return @tzinfo if @tzinfo     RAILS_DEFAULT_LOGGER.debug("TZINFO ASSIGN TO #{MAPPING[name]}")     begin       @tzinfo = MAPPING[name]     rescue TypeError => type_error       RAILS_DEFAULT_LOGGER.debug("TZINFO TYPE ERROR #{type_error}")       raise type_error     end     RAILS_DEFAULT_LOGGER.debug("TZINFO ASSIGNED TO #{@tzinfo}")     if String === @tzinfo       @tzinfo = TZInfo::Timezone.get(@tzinfo)       MAPPING[name] = @tzinfo     end     @tzinfo   end

When the error occurs, the following makes it to the log:

TZINFO STATE '' class NilClass frozen? false TZINFO ASSIGN TO Europe/Amsterdam TZINFO TYPE ERROR can't modify frozen object

Which means, that @tzinfo is nil, and yet, the line

    @tzinfo = MAPPING[name]

Causes a TypeError. MAPPING is a hash. I'm mildly confused. Anyone able to shed some light on what might be the issue or how to dig further into the problem?

ruby 1.8.4 (2005-12-24) [x86_64-linux]

Thanks.

Morten

Morten,

Not sure what's causing this exactly. Why are you trying to load the tzinfo from a MAPPING hash?

Check out the timezone code in mephisto for a really slick way to handle timezones. It helped me quite a bit.

Hope this helps.

Zack,

Morten,

Not sure what's causing this exactly. Why are you trying to load the tzinfo from a MAPPING hash?

The code I'm trying to debug is actually tzinfo_timezone.rb, so the error occurs within the plugin. I just use it like:

In my user model:

  composed_of :tz, :class_name => 'TimeZone', :mapping => %w(time_zone name)

In my view:

  <%= format_date(@current_user.tz.utc_to_local(entry.created_at)) %>

The hash is part of tzinfo_timezone.rb's way of associating time zones with locations.

Thanks for the tip on Mephisto, I'll look into their way og handling time zones.

Br,

Morten

This line should be:

composed_of :tz, :class_name => 'TzinfoTimezone', :mapping => %w(time_zone name)

I think the mappings are slightly different between the two which would explain the intermittent crashes.

The tzinfo_timezone plugin, in the init.rb script, actually replaces Rails' TimeZone class with TzinfoTimezone, so using either one of those should work as the :class_name (I think?),

-tieg