I have been looking all through the documentation and can''t find anything to display the time in 12 hours format with an AM/PM option. Is there an option for datetime_select to do this? Or a plugin? Thanks! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Aug 20, 6:01 am, Ben Johnson <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I have been looking all through the documentation and can''t find > anything to display the time in 12 hours format with an AM/PM option. Is > there an option for datetime_select to do this? Or a plugin? >Look up the strftime function -- Procrastinx --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I have been looking all through the documentation and can''t find anything to display the time in 12 hours format with an AM/PM option. Is there an option for datetime_select to do this? Or a plugin? Thanks! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
see strftime http://www.ruby-doc.org/core/classes/Time.html#M000297 On Aug 21, 2007, at 5:14 PM, Ben Johnson wrote:> > I have been looking all through the documentation and can''t find > anything to display the time in 12 hours format with an AM/PM > option. Is > there an option for datetime_select to do this? Or a plugin? > > Thanks! > -- > Posted via http://www.ruby-forum.com/. > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Paul Hoehne wrote:> see strftime > > http://www.ruby-doc.org/core/classes/Time.html#M000297That does not help me with the datetime_select function. datetime_select is a helper that takes options to create select drop downs. It has a drop down with 0 - 23, which is military time. My users and I would prefer 12 hour time with AM and PM. I can not figure out how to do this with the datetime_select helper function. strftime doesnt help -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Sorry about that # File vendor/rails/actionpack/lib/action_view/helpers/ date_helper.rb, line 209 It seems as though it only goes from 0-23. You can define your own select_hour (my_select_hour) and basically: 209: def my_select_hour(datetime, options = {}) 210: val = datetime ? (datetime.kind_of?(Fixnum) ? datetime : datetime.hour) : '''' 211: if options[:use_hidden] 212: hidden_html(options[:field_name] || ''hour'', val, options) 213: else 214: hour_options = [] 215: 0.upto(23) do |hour| 216: hour_options << ((val == hour) ? 217: %(<option value="#{leading_zero_on_single_digits (hour)}" selected="selected">#{leading_zero_on_single_digits(hour)}</ option>\n) : 218: %(<option value="#{leading_zero_on_single_digits (hour)}">#{leading_zero_on_single_digits(hour)}</option>\n) 219: ) 220: end 221: select_html(options[:field_name] || ''hour'', hour_options, options) 222: end 223: end Change 217/218 to read something like %(<option value="#{leading_zero_on_single_digits(hour)}" selected="selected">#{ (hour == 0 ? 12 : ( hour > 12 ? hour - 12 : hour )) } #{( hour >= 12 ? "PM" : "AM")}</option>\n) : %(<option value="#{leading_zero_on_single_digits(hour)}">>#{ (hour == 0 ? 12 : ( hour > 12 ? hour - 12 : hour )) } #{( hour >= 12 ? "PM" : "AM")}</option>\n) On Aug 21, 2007, at 5:25 PM, Ben Johnson wrote:> > Paul Hoehne wrote: >> see strftime >> >> http://www.ruby-doc.org/core/classes/Time.html#M000297 > > That does not help me with the datetime_select function. > datetime_select > is a helper that takes options to create select drop downs. It has a > drop down with 0 - 23, which is military time. My users and I would > prefer 12 hour time with AM and PM. I can not figure out how to do > this > with the datetime_select helper function. strftime doesnt help > -- > Posted via http://www.ruby-forum.com/. > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Of all the things rails does, it can''t do a 12 hour time drop down. Thanks for your help! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> I have been looking all through the documentation and can''t find > anything to display the time in 12 hours format with an AM/PM option. Is > there an option for datetime_select to do this? Or a plugin?http://agilewebdevelopment.com/plugins/search?search=12+hour Perhaps the top two would do the trick? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Came across this post and wanted to add my own solution, which isn''t better than the above mentioned ones, just another option (also doesn''t require losing the original rails helper and/or installing another plugin). in application_helper.rb or something: def my_hour_select str = select_tag(''hour'',options_for_select([1,2,3,4,5,6,7,8,9,10,11,12]) end then in your view: <%= my_hour_select %> You could use the ''selected'' option from options_for_select and Time.now.hour to select the current hour if needed. You can then set the name of the select to match a column in your model for re-usability by adding an option to the method like so: def my_hour_select(field_name) str = select_tag(field_name,options_for_select([1,2,3,4,5,6,7,8,9,10,11,12]) end and in your view: <%= my_hour_select(''event[start_time]'' %> Cheers, divotdave -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> <%= my_hour_select(''event[start_time]'' %>Should read: <%= my_hour_select(''event[start_time]'') %> Cheers -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ben Johnson wrote:> I have been looking all through the documentation and can''t find > anything to display the time in 12 hours format with an AM/PM option. Is > there an option for datetime_select to do this? Or a plugin? > > Thanks!Ben, Any luck on a solution to your post? I''m also having the same problem. Thanks, John -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Ben Johnson wrote:> I have been looking all through the documentation and can''t find > anything to display the time in 12 hours format with an AM/PM option. Is > there an option for datetime_select to do this? Or a plugin?Personally, I think of the Rails date_select helpers in a similar way I think of scaffolding. It''s fine for "quick-n-dirty" entry of dates and times, but for a "real" application go find a decent calendar widget. One that supports entry of both date and time in a more intuitive and user friendly way. Here''s one example: http://github.com/timcharper/calendar_date_select (Demo: http://electronicholas.com/calendar) -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Robert Walker wrote:> Ben Johnson wrote: >> I have been looking all through the documentation and can''t find >> anything to display the time in 12 hours format with an AM/PM option. Is >> there an option for datetime_select to do this? Or a plugin? > > Personally, I think of the Rails date_select helpers in a similar way I > think of scaffolding. It''s fine for "quick-n-dirty" entry of dates and > times, but for a "real" application go find a decent calendar widget. > One that supports entry of both date and time in a more intuitive and > user friendly way. > > Here''s one example: > http://github.com/timcharper/calendar_date_select (Demo: > http://electronicholas.com/calendar)Thanks! I like the date and time option with the calendar widget. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.