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.
September 20th, 2011 - 12:11
Just ran into this today. It’s actually the %e that is adding a space behind it. If the day was 2 digits (e.g. May 17) it won’t add a leading space. So smashing the strftime together won’t work for all dates.
PS. OS X behaves this way, on Linux there aren’t any leading spaces.