<% if schedule.date_scheduled.strftime(’%I:%M %p’) == ‘12:00 AM’ %>
TBA |
<% else %>
<%=h schedule.date_scheduled.strftime('%I:%M
%p') %> |
<% end %>
Works fine - datetime formats that are say “2009-06-30 17:30:00” will
show up as:
=> 05:30 PM
But if I change this to a 12-hour clock without the leading 0 using
schedule.date_scheduled.strftime(’%l:%M %p’)
=>
… nothing…
If I’m not using the correct formatting string for a 12-hour clock
without the leading 0, which is the correct output?
Thanks.
2009/7/11 Älphä Blüë [email protected]:
=> 05:30 PM
But if I change this to a 12-hour clock without the leading 0 using
I don’t understand, when you say ‘you change this to a 12-hour clock’
what is it that you have changed? The value in schedule.date_scheduled
or what?
Colin
schedule.date_scheduled.strftime(’%I:%M %p’)
=> 05:30 PM
schedule.date_scheduled.strftime(’%l:%M %p’)
=> nothing…
… it should equal
schedule.date_scheduled.strftime(’%l:%M %p’)
=> 5:30 PM
I’m trying to remove the leading 0 off the hours slot…
2009/7/11 Älphä Blüë [email protected]:
schedule.date_scheduled.strftime(‘%I:%M %p’)
=> 05:30 PM
schedule.date_scheduled.strftime(‘%l:%M %p’)
=> nothing…
I thought I must be going blind as in gmail in FF the two lines above
look identical, it was only when I copied and pasted into my editor in
order to do a compare that I realised the first on is %
and the second is %. I don’t see lower case L in the
docs for strftime, which may explain the problem.
This link has some possibly helpful suggestions for removing the
leading zero: http://snippets.dzone.com/posts/show/2952
Colin
I had been looking at:
http://www.nullislove.com/2007/05/16/time-for-strftime/
If you scroll down towards the bottom, there’s a very large table that
contains the formats. I was trying to follow the one for 12-hour
without the leading number.
I guess this means I have to use gsub…
Am 11.07.2009 um 16:43 schrieb Colin L.:
Interestingly, in irb:
irb(main):006:0> Time.now.strftime("%I:%M %p") # upper case i
=> “03:39 PM”
irb(main):007:0> Time.now.strftime("%l:%M %p") # lower case l
=> " 3:39 PM"
Could it be that something on the way to the browser chokes on the
leading whitespace? Maybe try the code in script/console, and continue
adding stuff around your strftime(…) until you find the culprit.
Regards,
Felix
2009/7/11 Älphä Blüë [email protected]:
I had been looking at:
http://www.nullislove.com/2007/05/16/time-for-strftime/
Thanks for that, a very useful link.
If you scroll down towards the bottom, there’s a very large table that
contains the formats. Â I was trying to follow the one for 12-hour
without the leading number.
I guess this means I have to use gsub…
Interestingly, in irb:
irb(main):006:0> Time.now.strftime(“%I:%M %p”) # upper case i
=> “03:39 PM”
irb(main):007:0> Time.now.strftime(“%l:%M %p”) # lower case l
=> " 3:39 PM"
What class is your schedule.date_scheduled? (use
schedule.date_scheduled.class to find out)
Colin
Felix Schäfer wrote:
Am 11.07.2009 um 16:43 schrieb Colin L.:
Interestingly, in irb:
irb(main):006:0> Time.now.strftime("%I:%M %p") # upper case i
=> “03:39 PM”
irb(main):007:0> Time.now.strftime("%l:%M %p") # lower case l
=> " 3:39 PM"
Could it be that something on the way to the browser chokes on the
leading whitespace? Maybe try the code in script/console, and continue
adding stuff around your strftime(…) until you find the culprit.
Regards,
Felix
Felix if I test just using Time.now.strftime("%l:%M %p") I get
=> “”
I’m using Rails 2.3.2
I’m using Ruby 1.8.6 One click installer for windows
NM…
This actually does work:
schedule.date_scheduled.strftime(’%I:%M %p’).gsub(/0?(\d):/,’\1:’)
I had to place it in another place because I forgot I was looking for a
conditional. The %l does not work and it may just be ruby version
related. I’m sure that 1.9 came out with new time features and maybe
that’s part of them…
2009/7/11 Älphä Blüë [email protected]:
that’s part of them…
It is ok for me on ruby 1.8.7, rails 2.3.2.
Colin
On Sat, Jul 11, 2009 at 8:17 AM, Älphä
Blüë[email protected] wrote:
I had to place it in another place because I forgot I was looking for a
conditional. The %l does not work and it may just be ruby version
related. I’m sure that 1.9 came out with new time features and maybe
that’s part of them…
ripple:~ hassan$ ruby -v
ruby 1.8.6 (2008-03-03 patchlevel 114) [universal-darwin9.0]
ripple:~ hassan$ irb
irb(main):001:0> Time.now.strftime(“%I:%M %p”) # u/c I as in India
=> “08:46 AM”
irb(main):002:0> Time.now.strftime(“%l:%M %p”) # l/c l as in Lima
=> " 8:46 AM"
irb(main):003:0>
FWIW,
Hassan S. ------------------------ [email protected]
twitter: @hassan
I already solved this using gsub.
But, just to follow-through with this - I’m not lying when I did my
checks:
irb(main):001:0> Time.now.strftime("%I:%M %p")
=> “12:57 PM”
irb(main):002:0> Time.now.strftime("%l:%M %p")
=> “”
irb(main):003:0>
l = lower case (l)ima (l)ime (l)azy (l)ucky…
Again, it does not compute with my IRB and I’m using:
ruby 1.8.6 (2008-08-11 patchlevel 287) [i386-mswin32]
well the strange thing is I tried:
schedule.date_scheduled.strftime(’%I:%M %p’).gsub(/0?(\d):/,’\1:’)
… and it doesn’t remove the leading 0…
however… if I go to the rails console
parse
=> “08:00 AM”
parse.gsub(/0?(\d):/,’\1:’)
=> “8:00 AM”
… very strange and tested in all browsers so same behavior