I am creating a rails app and run into what seems like weird behavior. According to the Ruby documentation Time.strftime () ,% P and% p are valid parameters:
%p - Meridian indicator (``AM'' or ``PM'')
%P - Meridian indicator (``am'' or ``pm'')
Using the rails console (Rails 3.0.3, ruby ββ1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]) I observe the following behavior:
>> DateTime.now.strftime("%l:%M%P on %A %e %Y")
=> " 2:23pm on Tuesday 1 2011"
>> Time.now.strftime("%l:%M%P on %A %e %Y")
=> " 2:23P on Tuesday 1 2011"
>> Time.now.strftime("%l:%M%p on %A %e %Y")
=> " 2:23PM on Tuesday 1 2011"
>> 2.hours.ago.strftime("%l:%M%P on %A %e %Y")
=> "11:29P on Monday 28 2011"
Notice how, in DateTime.now.strftime,% P evaluates the expected lowercase pm. With Time.now.strftime,% P is displayed as uppercase P.
The last example uses the ActiveSupport :: TimeWithZone class, and it displays too incorrectly (2 hours ago in the morning).
Is this the expected behavior? Or should I find a mistake somewhere, and if so, where is it best?