For those of you cool enough to have time zone support in your pre-rails 2.1 app, here is how you can convert the tzinfo stuff to the new way.
In your application.rb change the set_timezone around filter to a before filter. Make sure it is called after there is a valid user.
In your users model you can remove the line that used to say: composed_of :tz, :class_name => ‘TZInfo::Timezone’, :mapping => %w( time_zone time_zone ).
Remember the helper method called “tz” which converts the times in columns to the user’s time? Remove it, this happens automatically now.
Delete the tz* plugins.
If you had something like this in your view: <%= time_zone_select ‘person’, :time_zone, TZInfo::Timezone.us_zones, :model => TZInfo::Timezone > change it to <= time_zone_select ‘person’, :time_zone, TimeZone.us_zones %>.
Trevor has created a nice little script that will migrate your existing users’ time zone data to the new format. (The string that holds the time zone data has changed in the new version, so we have to map the old strings to the new.)
One unresolved problem: If you used something like the previous helper method to display the drop down of time choices you find that what is returned in the new list is significantly shorter, and they all have different values. E.G. in the old list you would find things like: “America/New_York,” “Africa/Ndjamena,” and “Etc/GMT-7” but in the new list the items are like this: “Eastern Time (US & Canada),” “Nairobi,” and “Wellington.” The problem is that we need to convert the values in our production apps to the new values. I haven’t figured out a way to do this yet. If you open script/console in a < 2.1 app you can find the old values are generated via: TZInfo::Timezone.get(TZInfo::Timezone.all_identifiers0), which returns the first time zone. The to_s and name methods are what get called on the object to create the value and text for the options. In a 2.1 app, TimeZone.all7 is what get called to find the 8th time zone. (to_s and name are still what get called.) I haven’t yet figured out how to map the old to the new, assuming there is a way. If someone figures this out, please post in the comments and I’ll update this post.
One last bit of coolness.
The new method of doing time zones even works when rendering values from the model. So on those rare times when you need to render HTML from the model (like if you’re sending HTML via XMPP) you don’t have to jump through any hoops to make that happen.
If you wanted it to build a product you’d find a way to get time to work on it. If you really wanted to start that new hobby you’d sacrifice something to find the time and money to do it.
I'll define a "Wannabe Entrepreneur" as someone who has never made money from their businesses. Here are the different types of wannabes.
In the past few years I've built go-carts, built a 200+ sq ft workshop, written several eBooks. How do I create a life where I have time to work on side projects?
Receive 5 Software projects mistakes we have made over the years and how to avoid them.