Skip to content


Subversion checkout URL

You can clone with
Download ZIP


ActiveSupport::TimeWithZone#strftime responds incorrectly to %:z and %::z format strings #6962

pastafari opened this Issue · 2 comments

3 participants


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.

Test Case

irb> = "Eastern Time (US & Canada)"
=> "Eastern Time (US & Canada)"
irb> twz =
=> Wed, 04 Jul 2012 11:55:11 EDT -04:00
irb> twz.strftime('%z')
=> "-0400"
irb> twz.strftime('%:z')
=> "+00:00"
irb> twz.strftime('%::z')
=> "+00:00: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 =,
 => Thu, 09 Aug 2012 13:22:37 PDT -07:00 
1.9.3p125 :044 > twz.strftime('%Y-%m-%dT%H:%M:%S%:z')
 => "2012-08-09T13:22:37+00:00" 
1.9.3p125 :045 > twz.to_time.strftime('%Y-%m-%dT%H:%M:%S%:z')
 => "2012-08-09T20:22:37+00:00"
@kennyj kennyj referenced this issue from a commit in kennyj/rails
@kennyj kennyj 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 :)

@kennyj kennyj referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
@kennyj kennyj closed this in 4e715e3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.