Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

ActiveSupport::TimeWithZone strftime formatting lacks unpadded types

#4729

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"

Reported by Evan Dorn · May 30th, 2010 @ 01:00 AM

State: invalid
Milestone: 3.0.2
Assigned to: Santiago Pastorino Santiago Pastorino
Importance: Low

Activity

  1. Evan Dorn
    Evan Dorn

    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"

    May 30th, 2010 @ 01:04 AM

  2. Neeraj Singh
    Neeraj Singh

    I can confirm that this is an issue with rails3 too.

    May 30th, 2010 @ 04:35 AM

  3. Neeraj Singh
    Neeraj Singh

    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]
    

    May 30th, 2010 @ 04:41 AM

  4. Santiago Pastorino
    Santiago Pastorino
    • Milestone cleared.
    • State changed from new to open
    • Assigned user set to Santiago Pastorino

    Can someone provide failing tests?

    May 30th, 2010 @ 05:57 AM

  5. Santiago Pastorino
    Santiago Pastorino
    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.

    June 3rd, 2010 @ 08:54 AM

  6. Santiago Pastorino
    Santiago Pastorino
    • State changed from open to invalid

    I'm closing this ticket if you have troubles please mention again and i will reopen

    June 26th, 2010 @ 01:19 AM

  7. Evan Dorn
    Evan Dorn
    • 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]

    July 6th, 2010 @ 02:16 AM

  8. Evan Dorn
    Evan Dorn

    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

    July 6th, 2010 @ 02:32 AM

  9. Santiago Pastorino
    Santiago Pastorino

    Ok you're right Evan, and yeah reporting to ruby is the right way to go, thanks ;).

    July 6th, 2010 @ 06:00 PM

  10. Jeremy Kemper