Skip to content

Instantly share code, notes, and snippets.

@hakanensari
Created July 16, 2009 19:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hakanensari/148656 to your computer and use it in GitHub Desktop.
Save hakanensari/148656 to your computer and use it in GitHub Desktop.
def select_datetime_range(object_name, method, max_time, scheduled_at = nil)
if scheduled_at
default_date, default_hour = @thing.scheduled_at.strftime("%Y-%m-%d"), @thing.scheduled_at.hour
else
default_date, default_hour = "prompt", "prompt"
end
hours = [["Time", "prompt"]] + (0..23).collect { |hour| [("0" + hour.to_s)[-2, 2] + ":00", hour] }
html = ""
days = [["Date", "prompt"]] + (Time.now..max_time).step(1.day).collect { |day| [day.strftime("%b %d"), day.strftime("%Y-%m-%d")] }
html << select_tag("#{object_name}_#{method}_date", options_for_select(days, default_date), { :name => "#{object_name}[#{method}[date]" })
html << " &mdash; "
html << select_tag("#{object_name}_#{method}_hour", options_for_select(hours, default_hour), { :name => "#{object_name}[#{method}[time]" })
html
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment