<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: Migrate to the Rails Default Time Zones</title>
	<atom:link href="http://trevorturk.wordpress.com/2008/06/03/migrate-to-the-rails-default-time-zones/feed/" rel="self" type="application/rss+xml" />
	<link>http://trevorturk.wordpress.com/2008/06/03/migrate-to-the-rails-default-time-zones/</link>
	<description>A chess-playing machine of the late 18th century, promoted as an automaton but later proved a hoax.</description>
	<lastBuildDate>Wed, 08 Feb 2012 17:13:43 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: dates and times &#171; Darinmurray&#8217;s Weblog</title>
		<link>http://trevorturk.wordpress.com/2008/06/03/migrate-to-the-rails-default-time-zones/#comment-649</link>
		<dc:creator><![CDATA[dates and times &#171; Darinmurray&#8217;s Weblog]]></dc:creator>
		<pubDate>Sat, 01 Nov 2008 04:07:29 +0000</pubDate>
		<guid isPermaLink="false">http://almosteffortless.com/?p=680#comment-649</guid>
		<description><![CDATA[[...] Migrate to the Rails Default Time Zones - almost effortless [...] ]]></description>
		<content:encoded><![CDATA[<p>[...] Migrate to the Rails Default Time Zones &#8211; almost effortless [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: l8r &#187; Converting TzInfo timezones to Rails timezones</title>
		<link>http://trevorturk.wordpress.com/2008/06/03/migrate-to-the-rails-default-time-zones/#comment-648</link>
		<dc:creator><![CDATA[l8r &#187; Converting TzInfo timezones to Rails timezones]]></dc:creator>
		<pubDate>Wed, 30 Jul 2008 22:30:43 +0000</pubDate>
		<guid isPermaLink="false">http://almosteffortless.com/?p=680#comment-648</guid>
		<description><![CDATA[[...] over time, various tips have cropped up to convert old to new. But neither tip worked good for me; I found them too [...] ]]></description>
		<content:encoded><![CDATA[<p>[...] over time, various tips have cropped up to convert old to new. But neither tip worked good for me; I found them too [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Walter Horstman</title>
		<link>http://trevorturk.wordpress.com/2008/06/03/migrate-to-the-rails-default-time-zones/#comment-647</link>
		<dc:creator><![CDATA[Walter Horstman]]></dc:creator>
		<pubDate>Thu, 12 Jun 2008 15:22:38 +0000</pubDate>
		<guid isPermaLink="false">http://almosteffortless.com/?p=680#comment-647</guid>
		<description><![CDATA[First, thanks for this script. I was a bit surprised that there is a lot of cheering about the new Rails time zone support, but I bet there are a lot of projects using the old TZInfo stuff and how to convert your time zones then? When I used the above script, I found a lot of zones are missing in the new system.
 

 
One of the things that I found is that the original TZInfo GEM has more zones, so the TZInfo::Timezone.get call retrieves more zones (e.g. Europe/Oslo). I kept this GEM before I converted my data and after that I removed it (of course I want as little external stuff as needed).
 

 
But I also added something to select at least the same time zone (with a different city) in case the old time zone can&#039;t be found in TimeZone::MAPPING.
 

 
My migration looks like this (maybe it helps others), based on the example above. By the way, I kept the old time zone in a backup field, to make a backwards conversion possible (for the time being, that is).
 

 
  def self.up
 
    # convert all user time zones
 
    change_column :users, :timezone, :string, :limit =&gt; 40, :null =&gt; false, :default =&gt; &#039;London&#039;
 
    add_column :users, :old_timezone, :string, :limit =&gt; 40, :null =&gt; false, :default =&gt; &#039;Europe/London&#039;
 
    execute &#039;UPDATE users SET old_timezone = timezone&#039;
 

 
    User.all.each do &#124;user&#124;
 
      tz = TZInfo::Timezone.get(user.timezone) rescue TimeZone[user.timezone] &#124;&#124; TimeZone[&#039;UTC&#039;]
 
      if tz.is_a?(TZInfo::Timezone)
 
        linked_timezone = tz.instance_variable_get(&#039;@linked_timezone&#039;)
 
        name = linked_timezone ? linked_timezone.name : tz.name
 
        time_zone = TimeZone::MAPPING.index(name)
 
        if time_zone.nil?
 
          compatible_zones = TimeZone.all.select { &#124;t&#124; t.utc_offset == tz.current_period.offset.utc_total_offset }
 
          time_zone = compatible_zones.empty? ? &#039;UTC&#039; : compatible_zones.first.name
 
        end
 
      else
 
        time_zone = tz.name
 
      end
 
      user.update_attribute :timezone, time_zone
 
    end
 

 
  def self.down
 
    execute &#039;UPDATE users SET timezone = old_timezone&#039;
 
    remove_column :users, :old_timezone
 
    change_column :users, :timezone, :string, :limit =&gt; 40, :null =&gt; false, :default =&gt; &#039;Europe/London&#039;
 
  end
 

 
(My field in the users table is called timezone). ]]></description>
		<content:encoded><![CDATA[<p>First, thanks for this script. I was a bit surprised that there is a lot of cheering about the new Rails time zone support, but I bet there are a lot of projects using the old TZInfo stuff and how to convert your time zones then? When I used the above script, I found a lot of zones are missing in the new system.</p>
<p>One of the things that I found is that the original TZInfo GEM has more zones, so the TZInfo::Timezone.get call retrieves more zones (e.g. Europe/Oslo). I kept this GEM before I converted my data and after that I removed it (of course I want as little external stuff as needed).</p>
<p>But I also added something to select at least the same time zone (with a different city) in case the old time zone can&#039;t be found in TimeZone::MAPPING.</p>
<p>My migration looks like this (maybe it helps others), based on the example above. By the way, I kept the old time zone in a backup field, to make a backwards conversion possible (for the time being, that is).</p>
<p>  def self.up</p>
<p>    # convert all user time zones</p>
<p>    change_column :users, :timezone, :string, :limit =&gt; 40, :null =&gt; false, :default =&gt; &#039;London&#039;</p>
<p>    add_column :users, <img src='http://s1.wp.com/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> ld_timezone, :string, :limit =&gt; 40, :null =&gt; false, :default =&gt; &#039;Europe/London&#039;</p>
<p>    execute &#039;UPDATE users SET old_timezone = timezone&#039;</p>
<p>    User.all.each do |user|</p>
<p>      tz = TZInfo::Timezone.get(user.timezone) rescue TimeZone[user.timezone] || TimeZone[&#039;UTC&#039;]</p>
<p>      if tz.is_a?(TZInfo::Timezone)</p>
<p>        linked_timezone = tz.instance_variable_get(&#039;@linked_timezone&#039;)</p>
<p>        name = linked_timezone ? linked_timezone.name : tz.name</p>
<p>        time_zone = TimeZone::MAPPING.index(name)</p>
<p>        if time_zone.nil?</p>
<p>          compatible_zones = TimeZone.all.select { |t| t.utc_offset == tz.current_period.offset.utc_total_offset }</p>
<p>          time_zone = compatible_zones.empty? ? &#039;UTC&#039; : compatible_zones.first.name</p>
<p>        end</p>
<p>      else</p>
<p>        time_zone = tz.name</p>
<p>      end</p>
<p>      user.update_attribute :timezone, time_zone</p>
<p>    end</p>
<p>  def self.down</p>
<p>    execute &#039;UPDATE users SET timezone = old_timezone&#039;</p>
<p>    remove_column :users, <img src='http://s1.wp.com/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> ld_timezone</p>
<p>    change_column :users, :timezone, :string, :limit =&gt; 40, :null =&gt; false, :default =&gt; &#039;Europe/London&#039;</p>
<p>  end</p>
<p>(My field in the users table is called timezone).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joe Martinez</title>
		<link>http://trevorturk.wordpress.com/2008/06/03/migrate-to-the-rails-default-time-zones/#comment-646</link>
		<dc:creator><![CDATA[Joe Martinez]]></dc:creator>
		<pubDate>Wed, 04 Jun 2008 19:22:18 +0000</pubDate>
		<guid isPermaLink="false">http://almosteffortless.com/?p=680#comment-646</guid>
		<description><![CDATA[I wrote a migration to set the user&#039;s time zone by US state if you have a predominantly American user base.
 

 
You could change it&#039;s default to UTC. It doesn&#039;t have to do an update for every user record.
 

 
&quot;You can find it here.&quot;http://www.jrmiii.com/2008/6/3/quick-migration-to-set-user-time-zones-for-rails-2-1
 

 
Cheers ]]></description>
		<content:encoded><![CDATA[<p>I wrote a migration to set the user&#039;s time zone by US state if you have a predominantly American user base.</p>
<p>You could change it&#039;s default to UTC. It doesn&#039;t have to do an update for every user record.</p>
<p>&quot;You can find it here.&quot;<a href="http://www.jrmiii.com/2008/6/3/quick-migration-to-set-user-time-zones-for-rails-2-1" rel="nofollow">http://www.jrmiii.com/2008/6/3/quick-migration-to-set-user-time-zones-for-rails-2-1</a></p>
<p>Cheers</p>
]]></content:encoded>
	</item>
</channel>
</rss>

