diff options
Diffstat (limited to 'actionpack/lib/action_view/helpers/date_helper.rb')
-rw-r--r-- | actionpack/lib/action_view/helpers/date_helper.rb | 188 |
1 files changed, 94 insertions, 94 deletions
diff --git a/actionpack/lib/action_view/helpers/date_helper.rb b/actionpack/lib/action_view/helpers/date_helper.rb index 61e39afd8e..459f95bb73 100644 --- a/actionpack/lib/action_view/helpers/date_helper.rb +++ b/actionpack/lib/action_view/helpers/date_helper.rb @@ -19,7 +19,7 @@ module ActionView # of \date[month]. module DateHelper # Reports the approximate distance in time between two Time, Date or DateTime objects or integers as seconds. - # Pass <tt>:include_seconds => true</tt> if you want more detailed approximations when distance < 1 min, 29 secs. + # Pass <tt>include_seconds: true</tt> if you want more detailed approximations when distance < 1 min, 29 secs. # Distances are reported based on the following table: # # 0 <-> 29 secs # => less than a minute @@ -37,7 +37,7 @@ module ActionView # 1 yr, 9 months <-> 2 yr minus 1 sec # => almost 2 years # 2 yrs <-> max time or date # => (same rules as 1 yr) # - # With <tt>:include_seconds => true</tt> and the difference < 1 minute 29 seconds: + # With <tt>include_seconds: true</tt> and the difference < 1 minute 29 seconds: # 0-4 secs # => less than 5 seconds # 5-9 secs # => less than 10 seconds # 10-19 secs # => less than 20 seconds @@ -50,19 +50,19 @@ module ActionView # distance_of_time_in_words(from_time, from_time + 50.minutes) # => about 1 hour # distance_of_time_in_words(from_time, 50.minutes.from_now) # => about 1 hour # distance_of_time_in_words(from_time, from_time + 15.seconds) # => less than a minute - # distance_of_time_in_words(from_time, from_time + 15.seconds, :include_seconds => true) # => less than 20 seconds + # distance_of_time_in_words(from_time, from_time + 15.seconds, include_seconds: true) # => less than 20 seconds # distance_of_time_in_words(from_time, 3.years.from_now) # => about 3 years # distance_of_time_in_words(from_time, from_time + 60.hours) # => 3 days - # distance_of_time_in_words(from_time, from_time + 45.seconds, :include_seconds => true) # => less than a minute - # distance_of_time_in_words(from_time, from_time - 45.seconds, :include_seconds => true) # => less than a minute + # distance_of_time_in_words(from_time, from_time + 45.seconds, include_seconds: true) # => less than a minute + # distance_of_time_in_words(from_time, from_time - 45.seconds, include_seconds: true) # => less than a minute # distance_of_time_in_words(from_time, 76.seconds.from_now) # => 1 minute # distance_of_time_in_words(from_time, from_time + 1.year + 3.days) # => about 1 year # distance_of_time_in_words(from_time, from_time + 3.years + 6.months) # => over 3 years # distance_of_time_in_words(from_time, from_time + 4.years + 9.days + 30.minutes + 5.seconds) # => about 4 years # # to_time = Time.now + 6.years + 19.days - # distance_of_time_in_words(from_time, to_time, :include_seconds => true) # => about 6 years - # distance_of_time_in_words(to_time, from_time, :include_seconds => true) # => about 6 years + # distance_of_time_in_words(from_time, to_time, include_seconds: true) # => about 6 years + # distance_of_time_in_words(to_time, from_time, include_seconds: true) # => about 6 years # distance_of_time_in_words(Time.now, Time.now) # => less than a minute def distance_of_time_in_words(from_time, to_time = 0, include_seconds_or_options = {}, options = {}) if include_seconds_or_options.is_a?(Hash) @@ -147,7 +147,7 @@ module ActionView # time_ago_in_words(3.minutes.ago) # => 3 minutes # time_ago_in_words(Time.now - 15.hours) # => about 15 hours # time_ago_in_words(Time.now) # => less than a minute - # time_ago_in_words(Time.now, :include_seconds => true) # => less than 5 seconds + # time_ago_in_words(Time.now, include_seconds: true) # => less than 5 seconds # # from_time = Time.now - 3.days - 14.minutes - 25.seconds # time_ago_in_words(from_time) # => 3 days @@ -190,7 +190,7 @@ module ActionView # as a hidden field instead of showing a select field. # * <tt>:order</tt> - Set to an array containing <tt>:day</tt>, <tt>:month</tt> and <tt>:year</tt> to # customize the order in which the select fields are shown. If you leave out any of the symbols, the respective - # select will not be shown (like when you set <tt>:discard_xxx => true</tt>. Defaults to the order defined in + # select will not be shown (like when you set <tt>discard_xxx: true</tt>. Defaults to the order defined in # the respective locale (e.g. [:year, :month, :day] in the en locale that ships with Rails). # * <tt>:include_blank</tt> - Include a blank option in every select field so it's possible to set empty # dates. @@ -212,36 +212,36 @@ module ActionView # # # Generates a date select that when POSTed is stored in the article variable, in the written_on attribute, # # with the year in the year drop down box starting at 1995. - # date_select("article", "written_on", :start_year => 1995) + # date_select("article", "written_on", start_year: 1995) # # # Generates a date select that when POSTed is stored in the article variable, in the written_on attribute, # # with the year in the year drop down box starting at 1995, numbers used for months instead of words, # # and without a day select box. - # date_select("article", "written_on", :start_year => 1995, :use_month_numbers => true, - # :discard_day => true, :include_blank => true) + # date_select("article", "written_on", start_year: 1995, use_month_numbers: true, + # discard_day: true, include_blank: true) # # # Generates a date select that when POSTed is stored in the article variable, in the written_on attribute, # # with two digit numbers used for months and days. - # date_select("article", "written_on", :use_two_digit_numbers => true) + # date_select("article", "written_on", use_two_digit_numbers: true) # # # Generates a date select that when POSTed is stored in the article variable, in the written_on attribute # # with the fields ordered as day, month, year rather than month, day, year. - # date_select("article", "written_on", :order => [:day, :month, :year]) + # date_select("article", "written_on", order: [:day, :month, :year]) # # # Generates a date select that when POSTed is stored in the user variable, in the birthday attribute # # lacking a year field. - # date_select("user", "birthday", :order => [:month, :day]) + # date_select("user", "birthday", order: [:month, :day]) # # # Generates a date select that when POSTed is stored in the article variable, in the written_on attribute # # which is initially set to the date 3 days from the current date - # date_select("article", "written_on", :default => 3.days.from_now) + # date_select("article", "written_on", default: 3.days.from_now) # # # Generates a date select that when POSTed is stored in the credit_card variable, in the bill_due attribute # # that will have a default day of 20. - # date_select("credit_card", "bill_due", :default => { :day => 20 }) + # date_select("credit_card", "bill_due", default: { day: 20 }) # # # Generates a date select with custom prompts. - # date_select("article", "written_on", :prompt => { :day => 'Select day', :month => 'Select month', :year => 'Select year' }) + # date_select("article", "written_on", prompt: { day: 'Select day', month: 'Select month', year: 'Select year' }) # # The selects are prepared for multi-parameter assignment to an Active Record object. # @@ -267,18 +267,18 @@ module ActionView # # # Creates a time select tag with a seconds field that, when POSTed, will be stored in the article variables in # # the sunrise attribute. - # time_select("article", "start_time", :include_seconds => true) + # time_select("article", "start_time", include_seconds: true) # # # You can set the <tt>:minute_step</tt> to 15 which will give you: 00, 15, 30 and 45. - # time_select 'game', 'game_time', {:minute_step => 15} + # time_select 'game', 'game_time', {minute_step: 15} # - # # Creates a time select tag with a custom prompt. Use <tt>:prompt => true</tt> for generic prompts. - # time_select("article", "written_on", :prompt => {:hour => 'Choose hour', :minute => 'Choose minute', :second => 'Choose seconds'}) - # time_select("article", "written_on", :prompt => {:hour => true}) # generic prompt for hours - # time_select("article", "written_on", :prompt => true) # generic prompts for all + # # Creates a time select tag with a custom prompt. Use <tt>prompt: true</tt> for generic prompts. + # time_select("article", "written_on", prompt: {hour: 'Choose hour', minute: 'Choose minute', second: 'Choose seconds'}) + # time_select("article", "written_on", prompt: {hour: true}) # generic prompt for hours + # time_select("article", "written_on", prompt: true) # generic prompts for all # # # You can set :ampm option to true which will show the hours as: 12 PM, 01 AM .. 11 PM. - # time_select 'game', 'game_time', {:ampm => true} + # time_select 'game', 'game_time', {ampm: true} # # The selects are prepared for multi-parameter assignment to an Active Record object. # @@ -300,23 +300,23 @@ module ActionView # # # Generates a datetime select with a year select that starts at 1995 that, when POSTed, will be stored in the # # article variable in the written_on attribute. - # datetime_select("article", "written_on", :start_year => 1995) + # datetime_select("article", "written_on", start_year: 1995) # # # Generates a datetime select with a default value of 3 days from the current time that, when POSTed, will # # be stored in the trip variable in the departing attribute. - # datetime_select("trip", "departing", :default => 3.days.from_now) + # datetime_select("trip", "departing", default: 3.days.from_now) # # # Generate a datetime select with hours in the AM/PM format - # datetime_select("article", "written_on", :ampm => true) + # datetime_select("article", "written_on", ampm: true) # # # Generates a datetime select that discards the type that, when POSTed, will be stored in the article variable # # as the written_on attribute. - # datetime_select("article", "written_on", :discard_type => true) + # datetime_select("article", "written_on", discard_type: true) # - # # Generates a datetime select with a custom prompt. Use <tt>:prompt => true</tt> for generic prompts. - # datetime_select("article", "written_on", :prompt => {:day => 'Choose day', :month => 'Choose month', :year => 'Choose year'}) - # datetime_select("article", "written_on", :prompt => {:hour => true}) # generic prompt for hours - # datetime_select("article", "written_on", :prompt => true) # generic prompts for all + # # Generates a datetime select with a custom prompt. Use <tt>prompt: true</tt> for generic prompts. + # datetime_select("article", "written_on", prompt: {day: 'Choose day', month: 'Choose month', year: 'Choose year'}) + # datetime_select("article", "written_on", prompt: {hour: true}) # generic prompt for hours + # datetime_select("article", "written_on", prompt: true) # generic prompts for all # # The selects are prepared for multi-parameter assignment to an Active Record object. def datetime_select(object_name, method, options = {}, html_options = {}) @@ -342,32 +342,32 @@ module ActionView # # # Generates a datetime select that defaults to the datetime in my_date_time (four days after today) # # with the fields ordered year, month, day rather than month, day, year. - # select_datetime(my_date_time, :order => [:year, :month, :day]) + # select_datetime(my_date_time, order: [:year, :month, :day]) # # # Generates a datetime select that defaults to the datetime in my_date_time (four days after today) # # with a '/' between each date field. - # select_datetime(my_date_time, :date_separator => '/') + # select_datetime(my_date_time, date_separator: '/') # # # Generates a datetime select that defaults to the datetime in my_date_time (four days after today) # # with a date fields separated by '/', time fields separated by '' and the date and time fields # # separated by a comma (','). - # select_datetime(my_date_time, :date_separator => '/', :time_separator => '', :datetime_separator => ',') + # select_datetime(my_date_time, date_separator: '/', time_separator: '', datetime_separator: ',') # # # Generates a datetime select that discards the type of the field and defaults to the datetime in # # my_date_time (four days after today) - # select_datetime(my_date_time, :discard_type => true) + # select_datetime(my_date_time, discard_type: true) # # # Generate a datetime field with hours in the AM/PM format - # select_datetime(my_date_time, :ampm => true) + # select_datetime(my_date_time, ampm: true) # # # Generates a datetime select that defaults to the datetime in my_date_time (four days after today) # # prefixed with 'payday' rather than 'date' - # select_datetime(my_date_time, :prefix => 'payday') + # select_datetime(my_date_time, prefix: 'payday') # - # # Generates a datetime select with a custom prompt. Use <tt>:prompt => true</tt> for generic prompts. - # select_datetime(my_date_time, :prompt => {:day => 'Choose day', :month => 'Choose month', :year => 'Choose year'}) - # select_datetime(my_date_time, :prompt => {:hour => true}) # generic prompt for hours - # select_datetime(my_date_time, :prompt => true) # generic prompts for all + # # Generates a datetime select with a custom prompt. Use <tt>prompt: true</tt> for generic prompts. + # select_datetime(my_date_time, prompt: {day: 'Choose day', month: 'Choose month', year: 'Choose year'}) + # select_datetime(my_date_time, prompt: {hour: true}) # generic prompt for hours + # select_datetime(my_date_time, prompt: true) # generic prompts for all def select_datetime(datetime = Time.current, options = {}, html_options = {}) DateTimeSelector.new(datetime, options, html_options).select_datetime end @@ -389,24 +389,24 @@ module ActionView # # # Generates a date select that defaults to the date in my_date (six days after today) # # with the fields ordered year, month, day rather than month, day, year. - # select_date(my_date, :order => [:year, :month, :day]) + # select_date(my_date, order: [:year, :month, :day]) # # # Generates a date select that discards the type of the field and defaults to the date in # # my_date (six days after today). - # select_date(my_date, :discard_type => true) + # select_date(my_date, discard_type: true) # # # Generates a date select that defaults to the date in my_date, # # which has fields separated by '/'. - # select_date(my_date, :date_separator => '/') + # select_date(my_date, date_separator: '/') # # # Generates a date select that defaults to the datetime in my_date (six days after today) # # prefixed with 'payday' rather than 'date'. - # select_date(my_date, :prefix => 'payday') + # select_date(my_date, prefix: 'payday') # - # # Generates a date select with a custom prompt. Use <tt>:prompt => true</tt> for generic prompts. - # select_date(my_date, :prompt => {:day => 'Choose day', :month => 'Choose month', :year => 'Choose year'}) - # select_date(my_date, :prompt => {:hour => true}) # generic prompt for hours - # select_date(my_date, :prompt => true) # generic prompts for all + # # Generates a date select with a custom prompt. Use <tt>prompt: true</tt> for generic prompts. + # select_date(my_date, prompt: {day: 'Choose day', month: 'Choose month', year: 'Choose year'}) + # select_date(my_date, prompt: {hour: true}) # generic prompt for hours + # select_date(my_date, prompt: true) # generic prompts for all def select_date(date = Date.current, options = {}, html_options = {}) DateTimeSelector.new(date, options, html_options).select_date end @@ -427,26 +427,26 @@ module ActionView # # # Generates a time select that defaults to the time in my_time, # # which has fields separated by ':'. - # select_time(my_time, :time_separator => ':') + # select_time(my_time, time_separator: ':') # # # Generates a time select that defaults to the time in my_time, # # that also includes an input for seconds. - # select_time(my_time, :include_seconds => true) + # select_time(my_time, include_seconds: true) # # # Generates a time select that defaults to the time in my_time, that has fields # # separated by ':' and includes an input for seconds. - # select_time(my_time, :time_separator => ':', :include_seconds => true) + # select_time(my_time, time_separator: ':', include_seconds: true) # # # Generate a time select field with hours in the AM/PM format - # select_time(my_time, :ampm => true) + # select_time(my_time, ampm: true) # # # Generates a time select field with hours that range from 2 to 14 - # select_time(my_time, :start_hour => 2, :end_hour => 14) + # select_time(my_time, start_hour: 2, end_hour: 14) # # # Generates a time select with a custom prompt. Use <tt>:prompt</tt> to true for generic prompts. - # select_time(my_time, :prompt => {:day => 'Choose day', :month => 'Choose month', :year => 'Choose year'}) - # select_time(my_time, :prompt => {:hour => true}) # generic prompt for hours - # select_time(my_time, :prompt => true) # generic prompts for all + # select_time(my_time, prompt: {day: 'Choose day', month: 'Choose month', year: 'Choose year'}) + # select_time(my_time, prompt: {hour: true}) # generic prompt for hours + # select_time(my_time, prompt: true) # generic prompts for all def select_time(datetime = Time.current, options = {}, html_options = {}) DateTimeSelector.new(datetime, options, html_options).select_time end @@ -465,11 +465,11 @@ module ActionView # # # Generates a select field for seconds that defaults to the seconds for the time in my_time # # that is named 'interval' rather than 'second'. - # select_second(my_time, :field_name => 'interval') + # select_second(my_time, field_name: 'interval') # - # # Generates a select field for seconds with a custom prompt. Use <tt>:prompt => true</tt> for a + # # Generates a select field for seconds with a custom prompt. Use <tt>prompt: true</tt> for a # # generic prompt. - # select_second(14, :prompt => 'Choose seconds') + # select_second(14, prompt: 'Choose seconds') def select_second(datetime, options = {}, html_options = {}) DateTimeSelector.new(datetime, options, html_options).select_second end @@ -489,11 +489,11 @@ module ActionView # # # Generates a select field for minutes that defaults to the minutes for the time in my_time # # that is named 'moment' rather than 'minute'. - # select_minute(my_time, :field_name => 'moment') + # select_minute(my_time, field_name: 'moment') # - # # Generates a select field for minutes with a custom prompt. Use <tt>:prompt => true</tt> for a + # # Generates a select field for minutes with a custom prompt. Use <tt>prompt: true</tt> for a # # generic prompt. - # select_minute(14, :prompt => 'Choose minutes') + # select_minute(14, prompt: 'Choose minutes') def select_minute(datetime, options = {}, html_options = {}) DateTimeSelector.new(datetime, options, html_options).select_minute end @@ -512,17 +512,17 @@ module ActionView # # # Generates a select field for hours that defaults to the hour for the time in my_time # # that is named 'stride' rather than 'hour'. - # select_hour(my_time, :field_name => 'stride') + # select_hour(my_time, field_name: 'stride') # - # # Generates a select field for hours with a custom prompt. Use <tt>:prompt => true</tt> for a + # # Generates a select field for hours with a custom prompt. Use <tt>prompt: true</tt> for a # # generic prompt. - # select_hour(13, :prompt => 'Choose hour') + # select_hour(13, prompt: 'Choose hour') # # # Generate a select field for hours in the AM/PM format - # select_hour(my_time, :ampm => true) + # select_hour(my_time, ampm: true) # # # Generates a select field that includes options for hours from 2 to 14. - # select_hour(my_time, :start_hour => 2, :end_hour => 14) + # select_hour(my_time, start_hour: 2, end_hour: 14) def select_hour(datetime, options = {}, html_options = {}) DateTimeSelector.new(datetime, options, html_options).select_hour end @@ -541,15 +541,15 @@ module ActionView # select_day(5) # # # Generates a select field for days that defaults to the number given, but displays it with two digits. - # select_day(5, :use_two_digit_numbers => true) + # select_day(5, use_two_digit_numbers: true) # # # Generates a select field for days that defaults to the day for the date in my_date # # that is named 'due' rather than 'day'. - # select_day(my_time, :field_name => 'due') + # select_day(my_time, field_name: 'due') # - # # Generates a select field for days with a custom prompt. Use <tt>:prompt => true</tt> for a + # # Generates a select field for days with a custom prompt. Use <tt>prompt: true</tt> for a # # generic prompt. - # select_day(5, :prompt => 'Choose day') + # select_day(5, prompt: 'Choose day') def select_day(date, options = {}, html_options = {}) DateTimeSelector.new(date, options, html_options).select_day end @@ -570,31 +570,31 @@ module ActionView # # # Generates a select field for months that defaults to the current month that # # is named "start" rather than "month". - # select_month(Date.today, :field_name => 'start') + # select_month(Date.today, field_name: 'start') # # # Generates a select field for months that defaults to the current month that # # will use keys like "1", "3". - # select_month(Date.today, :use_month_numbers => true) + # select_month(Date.today, use_month_numbers: true) # # # Generates a select field for months that defaults to the current month that # # will use keys like "1 - January", "3 - March". - # select_month(Date.today, :add_month_numbers => true) + # select_month(Date.today, add_month_numbers: true) # # # Generates a select field for months that defaults to the current month that # # will use keys like "Jan", "Mar". - # select_month(Date.today, :use_short_month => true) + # select_month(Date.today, use_short_month: true) # # # Generates a select field for months that defaults to the current month that # # will use keys like "Januar", "Marts." - # select_month(Date.today, :use_month_names => %w(Januar Februar Marts ...)) + # select_month(Date.today, use_month_names: %w(Januar Februar Marts ...)) # # # Generates a select field for months that defaults to the current month that # # will use keys with two digit numbers like "01", "03". - # select_month(Date.today, :use_two_digit_numbers => true) + # select_month(Date.today, use_two_digit_numbers: true) # - # # Generates a select field for months with a custom prompt. Use <tt>:prompt => true</tt> for a + # # Generates a select field for months with a custom prompt. Use <tt>prompt: true</tt> for a # # generic prompt. - # select_month(14, :prompt => 'Choose month') + # select_month(14, prompt: 'Choose month') def select_month(date, options = {}, html_options = {}) DateTimeSelector.new(date, options, html_options).select_month end @@ -607,23 +607,23 @@ module ActionView # # # Generates a select field for years that defaults to the current year that # # has ascending year values. - # select_year(Date.today, :start_year => 1992, :end_year => 2007) + # select_year(Date.today, start_year: 1992, end_year: 2007) # # # Generates a select field for years that defaults to the current year that # # is named 'birth' rather than 'year'. - # select_year(Date.today, :field_name => 'birth') + # select_year(Date.today, field_name: 'birth') # # # Generates a select field for years that defaults to the current year that # # has descending year values. - # select_year(Date.today, :start_year => 2005, :end_year => 1900) + # select_year(Date.today, start_year: 2005, end_year: 1900) # # # Generates a select field for years that defaults to the year 2006 that # # has ascending year values. - # select_year(2006, :start_year => 2000, :end_year => 2010) + # select_year(2006, start_year: 2000, end_year: 2010) # - # # Generates a select field for years with a custom prompt. Use <tt>:prompt => true</tt> for a + # # Generates a select field for years with a custom prompt. Use <tt>prompt: true</tt> for a # # generic prompt. - # select_year(14, :prompt => 'Choose year') + # select_year(14, prompt: 'Choose year') def select_year(date, options = {}, html_options = {}) DateTimeSelector.new(date, options, html_options).select_year end @@ -636,7 +636,7 @@ module ActionView # <time datetime="2010-11-04T17:55:45+01:00">November 04, 2010 17:55</time> # time_tag Date.yesterday, 'Yesterday' # => # <time datetime="2010-11-03">Yesterday</time> - # time_tag Date.today, :pubdate => true # => + # time_tag Date.today, pubdate: true # => # <time datetime="2010-11-04" pubdate="pubdate">November 04, 2010</time> # # <%= time_tag Time.now do %> @@ -893,19 +893,19 @@ module ActionView end # Build select option html from date value and options. - # build_options(15, :start => 1, :end => 31) + # build_options(15, start: 1, end: 31) # => "<option value="1">1</option> # <option value="2">2</option> # <option value="3">3</option>..." # - # If <tt>:use_two_digit_numbers => true</tt> option is passed - # build_options(15, :start => 1, :end => 31, :use_two_digit_numbers => true) + # If <tt>use_two_digit_numbers: true</tt> option is passed + # build_options(15, start: 1, end: 31, use_two_digit_numbers: true) # => "<option value="1">01</option> # <option value="2">02</option> # <option value="3">03</option>..." # # If <tt>:step</tt> options is passed - # build_options(15, :start => 1, :end => 31, :step => 2) + # build_options(15, start: 1, end: 31, step: 2) # => "<option value="1">1</option> # <option value="3">3</option> # <option value="5">5</option>..." @@ -954,7 +954,7 @@ module ActionView end # Builds a prompt option tag with supplied options or from default options. - # prompt_option_tag(:month, :prompt => 'Select month') + # prompt_option_tag(:month, prompt: 'Select month') # => "<option value="">Select month</option>" def prompt_option_tag(type, options) prompt = case options |