<?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/"
		>
<channel>
	<title>Comments on: Migrate to the Rails Default Time Zones</title>
	<atom:link href="http://trevorturk.com/2008/06/03/migrate-to-the-rails-default-time-zones/feed/" rel="self" type="application/rss+xml" />
	<link>http://trevorturk.com/2008/06/03/migrate-to-the-rails-default-time-zones/</link>
	<description></description>
	<lastBuildDate>Tue, 07 Sep 2010 17:45:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: dates and times &#171; Darinmurray&#8217;s Weblog</title>
		<link>http://trevorturk.com/2008/06/03/migrate-to-the-rails-default-time-zones/#comment-66764</link>
		<dc:creator>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-66764</guid>
		<description>[...] 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.com/2008/06/03/migrate-to-the-rails-default-time-zones/#comment-66573</link>
		<dc:creator>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-66573</guid>
		<description>[...] 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.com/2008/06/03/migrate-to-the-rails-default-time-zones/#comment-66519</link>
		<dc:creator>Walter Horstman</dc:creator>
		<pubDate>Thu, 12 Jun 2008 22:22:38 +0000</pubDate>
		<guid isPermaLink="false">http://almosteffortless.com/?p=680#comment-66519</guid>
		<description>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&#8217;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<br />
    # convert all user time zones<br />
    change_column :users, :timezone, :string, :limit =&gt; 40, :null =&gt; false, :default =&gt; &#8216;London&#8217;<br />
    add_column :users, :old_timezone, :string, :limit =&gt; 40, :null =&gt; false, :default =&gt; &#8216;Europe/London&#8217;<br />
    execute &#8216;UPDATE users SET old_timezone = timezone&#8217;</p>
<p>    User.all.each do |user|<br />
      tz = TZInfo::Timezone.get(user.timezone) rescue TimeZone[user.timezone] || TimeZone['UTC']<br />
      if tz.is_a?(TZInfo::Timezone)<br />
        linked_timezone = tz.instance_variable_get(&#8216;@linked_timezone&#8217;)<br />
        name = linked_timezone ? linked_timezone.name : tz.name<br />
        time_zone = TimeZone::MAPPING.index(name)<br />
        if time_zone.nil?<br />
          compatible_zones = TimeZone.all.select { |t| t.utc_offset == tz.current_period.offset.utc_total_offset }<br />
          time_zone = compatible_zones.empty? ? &#8216;UTC&#8217; : compatible_zones.first.name<br />
        end<br />
      else<br />
        time_zone = tz.name<br />
      end<br />
      user.update_attribute :timezone, time_zone<br />
    end</p>
<p>  def self.down<br />
    execute &#8216;UPDATE users SET timezone = old_timezone&#8217;<br />
    remove_column :users, :old_timezone<br />
    change_column :users, :timezone, :string, :limit =&gt; 40, :null =&gt; false, :default =&gt; &#8216;Europe/London&#8217;<br />
  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.com/2008/06/03/migrate-to-the-rails-default-time-zones/#comment-66506</link>
		<dc:creator>Joe Martinez</dc:creator>
		<pubDate>Thu, 05 Jun 2008 02:22:18 +0000</pubDate>
		<guid isPermaLink="false">http://almosteffortless.com/?p=680#comment-66506</guid>
		<description>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&#8217;s time zone by US state if you have a predominantly American user base.</p>
<p>You could change it&#8217;s default to UTC. It doesn&#8217;t have to do an update for every user record.</p>
<p>&#8220;You can find it here.&#8221;http://www.jrmiii.com/2008/6/3/quick-migration-to-set-user-time-zones-for-rails-2-1</p>
<p>Cheers</p>
]]></content:encoded>
	</item>
</channel>
</rss>
