method
advance
v3.2.8 -
Show latest stable
- Class:
Time
advance(options)public
Uses Date to provide precise Time calculations for years, months, and days. The options parameter takes a hash with any of these keys: :years, :months, :weeks, :days, :hours, :minutes, :seconds.
# File activesupport/lib/active_support/core_ext/time/calculations.rb, line 90
def advance(options)
unless options[:weeks].nil?
options[:weeks], partial_weeks = options[:weeks].divmod(1)
options[:days] = (options[:days] || 0) + 7 * partial_weeks
end
unless options[:days].nil?
options[:days], partial_days = options[:days].divmod(1)
options[:hours] = (options[:hours] || 0) + 24 * partial_days
end
d = to_date.advance(options)
time_advanced_by_date = change(:year => d.year, :month => d.month, :day => d.day)
seconds_to_advance = (options[:seconds] || 0) + (options[:minutes] || 0) * 60 + (options[:hours] || 0) * 3600
seconds_to_advance == 0 ? time_advanced_by_date : time_advanced_by_date.since(seconds_to_advance)
end Related methods
- Instance methods
- +
- -
- <=>
- _dump
- _dump_without_utc_flag
- _dump_without_zone
- acts_like_time?
- advance
- ago
- all_day
- all_month
- all_quarter
- all_week
- all_year
- as_json
- at_beginning_of_day
- at_beginning_of_hour
- at_beginning_of_month
- at_beginning_of_quarter
- at_beginning_of_week
- at_beginning_of_year
- at_end_of_month
- at_end_of_quarter
- at_end_of_week
- at_end_of_year
- at_midnight
- beginning_of_day
- beginning_of_hour
- beginning_of_month
- beginning_of_quarter
- beginning_of_week
- beginning_of_year
- change
- compare_with_coercion
- compare_without_coercion
- days_to_week_start
- end_of_day
- end_of_hour
- end_of_month
- end_of_quarter
- end_of_week
- end_of_year
- eql?
- eql_with_coercion
- eql_without_coercion
- formatted_offset
- future?
- in
- in_time_zone
- midnight
- minus_with_coercion
- minus_with_duration
- minus_without_coercion
- minus_without_duration
- monday
- months_ago
- months_since
- next_month
- next_week
- next_year
- past?
- plus_with_duration
- plus_without_duration
- prev_month
- prev_week
- prev_year
- seconds_since_midnight
- since
- sunday
- to_date
- to_datetime
- to_default_s
- to_formatted_s
- to_s
- to_time
- today?
- tomorrow
- weeks_ago
- years_ago
- years_since
- yesterday
- Class methods
- ===
- _load
- _load_without_utc_flag
- _load_without_zone
- current
- days_in_month
- find_zone
- find_zone!
- local_time
- time_with_datetime_fallback
- use_zone
- utc_time
- zone
- zone=