Adventures into CouchDB and Rails

February 6, 2009

Rails Time Zone Bug — An Edge Case

Filed under: Uncategorized — zdzolton @ 1:02 am

Premise

I have found a Mac OS X-specific edge case in the Rails time zone support.

Evidence

irb(main):001:0> require 'rubygems'; require 'activesupport'
=> true
irb(main):002:0> ENV['TZ'] = 'US/Central'
=> "US/Central"
irb(main):003:0> t = Time.now
=> Thu Feb 05 16:03:56 -0600 2009
irb(main):004:0> t.to_s :json
=> "Thu Feb 05 16:03:56 -0600 2009"
irb(main):005:0> t.to_s :rfc822
=> "Thu, 05 Feb 2009 16:03:56 -0500"

Notice that when invoking Time#to_s method, and providing the parameter :rfc822, the UTC

Solution

A small modification to the :rfc822 format specifier in DATE_FORMATS hash, defined within the ActiveSupport::CoreExtensions::Time::Conversions module, does the trick.

Specifically, line #13 of activesupport/lib/active_support/core_ext/time/conversions.rb:

          :rfc822       => "%a, %d %b %Y %H:%M:%S %z"

Should be changed to this:

          :rfc822       => lambda { |time| time.strftime("%a, %d %b %Y %H:%M:%S #{time.formatted_offset(false)}") } 

Background

This is related to my previous blog post, in which I found a similar bug in the serialization of CouchSurfer::Model timestamps.

I am currently testing this on Mac OS X 10.5.6.

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: