Repository: rails/rails
File: actionview/lib/action_view/helpers/date_helper.rb (Ruby)

Code before:
      #   from_time = (3.days + 14.minutes + 25.seconds).ago
      #   time_ago_in_words(from_time)      # => 3 days
      #
      # Note that you cannot pass a <tt>Numeric</tt> value to <tt>time_ago_in_words</tt>.
      #
      def time_ago_in_words(from_time, options = {})
        distance_of_time_in_words(from_time, Time.now, options)
      end

      alias_method :distance_of_time_in_words_to_now, :time_ago_in_words

      # Like <tt>time_ago_in_words</tt>, but adds a prefix/suffix depending on whether the time is in the past or future.
      # You can use the <tt>scope</tt> option to customize the translation scope. All other options
      # are forwarded to <tt>time_ago_in_words</tt>.
      #
      #   relative_time_in_words(3.minutes.from_now) # => "in 3 minutes"
      #   relative_time_in_words(3.minutes.ago) # => "3 minutes ago"
      #   relative_time_in_words(10.seconds.ago, include_seconds: true) # => "less than 10 seconds ago"
      #
      # See also #time_ago_in_words
      def relative_time_in_words(from_time, options = {})
        options = { scope: :'datetime.relative' }.merge(options)
        time = time_ago_in_words(from_time, options.except(:scope))
        key = from_time > Time.now ? :future : :past

        I18n.t(key, time: time, scope: options[:scope], locale: options[:locale])
      end

      # Returns a set of select tags (one for year, month, and day) pre-selected for accessing a specified date-based
      # attribute (identified by +method+) on an object assigned to the template (identified by +object+).
      #
      # ==== Options
      # * <tt>:use_month_numbers</tt> - Set to true if you want to use month numbers rather than month names (e.g.
      #   "2" instead of "February").
      # * <tt>:use_two_digit_numbers</tt> - Set to true if you want to display two digit month and day numbers (e.g.
      #   "02" instead of "February" and "08" instead of "8").
      # * <tt>:use_short_month</tt>   - Set to true if you want to use abbreviated month names instead of full
      #   month names (e.g. "Feb" instead of "February").
      # * <tt>:add_month_numbers</tt>  - Set to true if you want to use both month numbers and month names (e.g.
      #   "2 - February" instead of "February").
      # * <tt>:use_month_names</tt>   - Set to an array with 12 month names if you want to customize month names.
      #   Note: You can also use Rails' i18n functionality for this.
      # * <tt>:month_format_string</tt> - Set to a format string. The string gets passed keys +:number+ (integer)
      #   and +:name+ (string). A format string would be something like "%{name} (%<number>02d)" for example.
      #   See <tt>Kernel.sprintf</tt> for documentation on format sequences.
      # * <tt>:date_separator</tt>    - Specifies a string to separate the date fields. Default is "" (i.e. nothing).
      # * <tt>:time_separator</tt>    - Specifies a string to separate the time fields. Default is " : ".
      # * <tt>:datetime_separator</tt>- Specifies a string to separate the date and time fields. Default is " &mdash; ".
      # * <tt>:start_year</tt>        - Set the start year for the year select. Default is <tt>Date.today.year - 5</tt> if
      #   you are creating new record. While editing existing record, <tt>:start_year</tt> defaults to
      #   the current selected year minus 5.

Review comment (suggestion):
```suggestion
        time = time_ago_in_words(from_time, options)
        key = from_time > Time.now ? :future : :past

        I18n.t(
          key,
          time: time,
          scope: options.fetch(:scope, :'datetime.relative'),
          locale: options[:locale],
        )
```

Is it really important not to forward the `scope` options? Because I think this could be streamlined.

Code after:
      #   from_time = (3.days + 14.minutes + 25.seconds).ago
      #   time_ago_in_words(from_time)      # => 3 days
      #
      # Note that you cannot pass a <tt>Numeric</tt> value to <tt>time_ago_in_words</tt>.
      #
      def time_ago_in_words(from_time, options = {})
        distance_of_time_in_words(from_time, Time.now, options)
      end

      alias_method :distance_of_time_in_words_to_now, :time_ago_in_words

      # Like <tt>time_ago_in_words</tt>, but adds a prefix/suffix depending on whether the time is in the past or future.
      # You can use the <tt>scope</tt> option to customize the translation scope. All other options
      # are forwarded to <tt>time_ago_in_words</tt>.
      #
      #   relative_time_in_words(3.minutes.from_now) # => "in 3 minutes"
      #   relative_time_in_words(3.minutes.ago) # => "3 minutes ago"
      #   relative_time_in_words(10.seconds.ago, include_seconds: true) # => "less than 10 seconds ago"
      #
      # See also #time_ago_in_words
      def relative_time_in_words(from_time, options = {})
        now = Time.now
        time = distance_of_time_in_words(from_time, now, options.except(:scope))
        key = from_time > now ? :future : :past

        I18n.t(key, time: time, scope: options.fetch(:scope, :'datetime.relative'), locale: options[:locale])
      end

      # Returns a set of select tags (one for year, month, and day) pre-selected for accessing a specified date-based
      # attribute (identified by +method+) on an object assigned to the template (identified by +object+).
      #
      # ==== Options
      # * <tt>:use_month_numbers</tt> - Set to true if you want to use month numbers rather than month names (e.g.
      #   "2" instead of "February").
      # * <tt>:use_two_digit_numbers</tt> - Set to true if you want to display two digit month and day numbers (e.g.
      #   "02" instead of "February" and "08" instead of "8").
      # * <tt>:use_short_month</tt>   - Set to true if you want to use abbreviated month names instead of full
      #   month names (e.g. "Feb" instead of "February").
      # * <tt>:add_month_numbers</tt>  - Set to true if you want to use both month numbers and month names (e.g.
      #   "2 - February" instead of "February").
      # * <tt>:use_month_names</tt>   - Set to an array with 12 month names if you want to customize month names.
      #   Note: You can also use Rails' i18n functionality for this.
      # * <tt>:month_format_string</tt> - Set to a format string. The string gets passed keys +:number+ (integer)
      #   and +:name+ (string). A format string would be something like "%{name} (%<number>02d)" for example.
      #   See <tt>Kernel.sprintf</tt> for documentation on format sequences.
      # * <tt>:date_separator</tt>    - Specifies a string to separate the date fields. Default is "" (i.e. nothing).
      # * <tt>:time_separator</tt>    - Specifies a string to separate the time fields. Default is " : ".
      # * <tt>:datetime_separator</tt>- Specifies a string to separate the date and time fields. Default is " &mdash; ".
      # * <tt>:start_year</tt>        - Set the start year for the year select. Default is <tt>Date.today.year - 5</tt> if
      #   you are creating new record. While editing existing record, <tt>:start_year</tt> defaults to
      #   the current selected year minus 5.