This project is archived and is in readonly mode.
ActiveSupport::TimeWithZone strftime formatting lacks unpadded types
Reported by Evan Dorn | May 30th, 2010 @ 01:00 AM | in 3.0.2
Plain ruby DateTime#strftime supports non-zero-padded month and day codes %-m and %-d, making it possible to generate "March 5, 2010" instead of "March 05, 2010". End users often prefer this format.
ActiveSupport::TimeWithZone#strftime does not support the same formats. Here's a simple reproduction of the flaw:
Loading development environment (Rails 2.3.8)
DateTime.parse("June 5th").strftime("%m %d") => "06 05" DateTime.parse("June 5th").strftime("%-m %-d") => "6 5" Time.zone.parse("June 5th").strftime("%m %d") => "06 05" Time.zone.parse("June 5th").strftime("%-m %-d") => "-m -d"
Comments and changes to this ticket
-
Evan Dorn May 30th, 2010 @ 01:04 AM
Attempt at better formatting:
Loading development environment (Rails 2.3.8)
>> DateTime.parse("June 5th").strftime("%m %d")
=> "06 05"
>> DateTime.parse("June 5th").strftime("%-m %-d")
=> "6 5"
>> Time.zone.parse("June 5th").strftime("%m %d")
=> "06 05"
>> Time.zone.parse("June 5th").strftime("%-m %-d")
=> "-m -d"
-
Neeraj Singh May 30th, 2010 @ 04:41 AM
It seems this is a ruby issue.
$ irb irb(main):001:0> Time.now.strftime("%-m %-d") => "-m -d" irb(main):002:0> Time.now.strftime("%m %d") => "05 29" irb(main):003:0> DateTime.now.strftime("%m %d") => "05 29" irb(main):004:0> DateTime.now.strftime("%-m %-d") => "5 29" irb(main):005:0> exit nsingh@ ~ $ ruby -v ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-darwin10.2.0]
-
Santiago Pastorino May 30th, 2010 @ 05:57 AM
- Milestone cleared.
- State changed from new to open
- Assigned user set to Santiago Pastorino
Can someone provide failing tests?
-
Santiago Pastorino June 3rd, 2010 @ 08:54 AM
santiago@debian:/tmp$ irb >> Time.now.strftime("%-m %-d") => "6 3" >> Time.now.strftime("%m %d") => "06 03" >> DateTime.now.strftime("%m %d") => "06 03" >> DateTime.now.strftime("%-m %-d") => "6 3" >> santiago@debian:/tmp$ ruby -v ruby 1.8.7 (2010-01-10 patchlevel 249) [x86_64-linux]
Seems to be fixed on the latest ruby 1.8.7, please check this. -
Santiago Pastorino June 26th, 2010 @ 01:19 AM
- State changed from open to invalid
I'm closing this ticket if you have troubles please mention again and i will reopen
-
Evan Dorn July 6th, 2010 @ 02:16 AM
- Importance changed from to Low
It's not the version of Ruby that matters. It's the platform. Works on linux, doesn't work on Mac.
On a mac, Snow Leopard installed:
[18:12:52 ~]$ irb ruby-1.8.7-p299 > Time.now.strftime("%-m %-d")
=> "-m -d" [18:13:25 ~]$ ruby -v ruby 1.8.7 (2010-06-23 patchlevel 299) [i686-darwin10.4.0]On a Ubuntu linux machine:
[18:13] evan@ci ~ $ irb irb(main):001:0> Time.now.strftime("%-m %-d")
=> "7 5"irb(main):002:0> exit
[18:15] evan@ci ~ $ ruby -v ruby 1.8.7 (2009-06-12 patchlevel 174) [x86_64-linux] -
Evan Dorn July 6th, 2010 @ 02:32 AM
Since it appears to be a platform-dependent Ruby issue, I reported this to the Ruby error tracker: http://redmine.ruby-lang.org/issues/show/3541
-
Santiago Pastorino July 6th, 2010 @ 06:00 PM
Ok you're right Evan, and yeah reporting to ruby is the right way to go, thanks ;).
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>