Cory O'Daniel – These are just words Software development, thoughts, and randomness

7May/101

Ruby 1.9 Date#strftime adds a space on %b

So, I had a spec failing in my integration suite and I couldn't figure out what the hell it was - EVERYTHING LOOKED LEGIT. I even logged into the site, and visually verified it. Whats the dilly?

I upgraded to ruby 1.9 from ruby 1.8 and apparently, when doing strftime on date, you get a free whitespace character with "%b"

1
2
3
# Ruby 1.8
irb(main):006:0> Date.today.strftime("%b %e, %Y")
=> "May 7, 2010"
1
2
irb(main):007:0> Date.today.strftime("%b %e, %Y")
=> "May  7, 2010" # TWO SPACES

Super dumb - wasted a good 10 minutes of my day because I could see the diff between:

1
2
"May  7, 2010"
"May 7, 2010"

In the middle of a web page full of other content.

Why the freebee space character on the %b? Dunno. I just smashed my stftime statement together and my specs are rolling.

1
Date.today.strftime("%b%e, %Y")

Uh, yeah - this is my bug report.

Post to Twitter Post to Digg Post to Facebook Post to Reddit Post to StumbleUpon