Minute options for datetime_select
Today I was on the verge of hacking together my own helper for a datetime_select, because my Event date selector in GuildAssist was presenting every single minute as an option – quite a waste as most events start on the hour, or on the half hour.
Before I started work on it, I thought it would be a good idea to look through the Rails source to see what options were available for the existing helper – I couldn’t find anything in the API and my googlefu wasn’t strong enough to turn out this gem:
Found by trawling through rails/actionpack/lib/action_view/helpers/date_helper.rb
Nice and elegant, as we’d expect from Rails, and now my events can start/finish in 15 minute intervals.

Jeff Ward said,
August 11, 2006 @ 1:06 am · Edit
Glad I found your post, thanks!
Now, what other options can we set that we don’t know about. The API documentation is terrible on this datetime_select thing.
Thank-you, thank-you!
keeran said,
August 11, 2006 @ 11:01 am · Edit
Hey Jeff, you’re welcome :)
Best thing to do is get down and dirty with the source code IMO - have a look for the date_helper.rb and trace through what’s going on with the code – on my (out of date) windows machine it was here:
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.3/lib/action_view/helpers
If you follow the method calls starting from def datetime_select you can see that it’s built up from lots of smaller methods, like select_year etc, each of which have their own set of options which get handed down from the top level method call.
When I’ve finished writing my latest post on dynamic navigation I’ll try to go through the obvious options hidden in there and write them up :)
Kee
Jeff Ward said,
August 18, 2006 @ 10:22 pm · Edit
Yes, please write them up. I’m sure I’m not the only one who will come across your thread.
I’d also love an option where you can specify a 12-hour clock with an am/pm drop-down too. Maybe somebody has a better helper out there.
Jeff
Chris Joslyn said,
April 23, 2008 @ 7:43 pm · Edit
Based on some quick Google research, it looks like the best way to get a 12-hour clock is to install a plugin that adds that option. I’ve found two that do just that.
I’ve used the one housed at: http://code.google.com/p/rails-twelve-hour-time-plugin
It seems to be working just fine in the Rails 2.0 development environment on my Ubuntu machine. In your code, it may look something like
true}%>
The one I haven’t used, but which comes with a whole lot of functionality, is FlexTimes, found here: http://rubyforge.org/projects/flextimes/
Chris Joslyn said,
April 23, 2008 @ 7:45 pm · Edit
Oops. Let’s try that code again:
Chris Joslyn said,
April 23, 2008 @ 7:47 pm · Edit
Alright, still no good. Sorry. Check out the examples at:
http://code.google.com/p/rails-twelve-hour-time-plugin
keeran said,
May 2, 2008 @ 7:02 pm · Edit
Cheers Chris,
Must admit this is all a bit out of date now. Rails has changed so much and I haven’t been posting in line with that :(
Thanks for the tip – I’ll check it out :)
K
elecnix said,
January 16, 2009 @ 4:50 am · Edit
One problem I have with minute_step is that it does not select the closest rounded minute by default. For example, if the time passed to it is 12:34, then it would not select anything, thus show 12:00.