The DateHelper
class contains two kinds of helper methods. There’s a
small set of methods for expressing times in somewhat more
human-friendly forms:
distance_of_time_in_words
Takes two time values and expresses how far apart they are in rough word descriptions rather than precise time notation—e.g., “2 days,” or “about 1 month,” or “less than a minute.”
distance_of_time_in_words_to_now
or
time_ago_in_words
Like distance_of_time_in_words
, but with the
to_time
always set to now
.
Most of DateHelper
’s methods,
though, create form fields for specifying times and dates. They’re kind
of clunky, but they may be useful for when you’re getting started or
when you feel like overriding them. Three of them are bound to
particular objects of type :date
,
:time
, or type :datetime
:
date_select
The date_select
method creates drop-down year, month, and day select fields bound
to a particular ActiveRecord object of type :date
.
datetime_select
The datetime_select
method creates drop-down year, month, day, hour, minute, and
second select fields bound to a particular ActiveRecord object of
type :datetime
.
time_select
The time_select
method creates drop-down hour, minute, and second select fields
bound to a particular ActiveRecord object of type :time
.
The rest of DateHelper
’s
methods create HTML form fields, but aren’t bound to any particular
ActiveRecord object:
select_date
The select_date
method creates drop-down year, month, and day select
fields.
select_datetime
The select_datetime
method creates drop-down year, month, day, hour, minute, and
second select fields.
select_day
The select_day
method
creates a drop-down field for day of the month (1–31).
select_hour
The select_hour
method creates a drop-down field for hours (0–23).
select_minute
The select_minute
method creates a drop-down field for minutes (0–59).
select_month
The select_month
method creates a drop-down field for month
(1–12).
select_second
The select_second
method creates a drop-down field for seconds
(0–59).
select_time
The select_time
method creates drop-down hour, minute, and second select
fields.
select_year
The select_year
method creates a drop-down field for year. By default it uses five
years on either side of the current or selected year, but you can
set start and end years through parameters.