Tuesday, November 29, 2011

In which I curse time zones

Just a reminder, Time is not always going to parse the timezone correctly from your system time. Ruby doc even goes to the trouble of explaining it quite well.
Loading development environment (Rails 3.1.3)
ree-1.8.7-2011.03 :001 > Time.zone
#<ActiveSupport::TimeZone:0x106494f88 @tzinfo=#<TZInfo::TimezoneProxy: Etc/UTC>, @name="UTC", @utc_offset=nil, @current_period=nil>
ree-1.8.7-2011.03 :002 > Time.now.zone
"CST"
ree-1.8.7-2011.03 :003 > Time.now.in_time_zone(Time.now.zone)
ArgumentError: Invalid Timezone: CST
	from /Users/chuckcollins/.rvm/gems/ree-1.8.7-2011.03@pharmmd/gems/activesupport-3.1.3/lib/active_support/core_ext/time/zones.rb:61:in `find_zone!'
	from /Users/chuckcollins/.rvm/gems/ree-1.8.7-2011.03@pharmmd/gems/activesupport-3.1.3/lib/active_support/core_ext/time/zones.rb:84:in `in_time_zone'
	from (irb):3
So when you are dealing with Time, make sure to use Time.zone.XXXXX for your time adventures.
blog comments powered by Disqus