Environment : Ruby(MRI) 1.9.3-p194 and Rails 3.2.6
ActiveRecord::TimeWithZone is supposed to be a drop in replacement for Ruby Time.
Howerver TimeWithZone#strftime does not respond correctly to the %:z and %::z format strings as per the Time#strftime documentation. It loses the time offset information as shown below.
irb> Time.zone = "Eastern Time (US & Canada)"
=> "Eastern Time (US & Canada)"
irb> twz = Time.zone.now
=> Wed, 04 Jul 2012 11:55:11 EDT -04:00
Pairing with @dhakadamit
I came across this issue yesterday. Thanks for reporting it @pastafari.
The workaround I used for my use case was to convert it to a Time first:
1.9.3p125 :043 > twz = ActiveSupport::TimeWithZone.new(Time.now.utc, Time.zone)
=> Thu, 09 Aug 2012 13:22:37 PDT -07:00
1.9.3p125 :044 > twz.strftime('%Y-%m-%dT%H:%M:%S%:z')
1.9.3p125 :045 > twz.to_time.strftime('%Y-%m-%dT%H:%M:%S%:z')
Fix #6962. AS::TimeWithZone#strftime responds incorrectly to %:z and …
…%::z format strings.
Hi guys ! Thanks for reporting.
I think I fix this issue. I already send PR #7703 :)