Module: ActionView::Helpers::DurationHelper
- Includes:
- DurationInWords::Methods
- Defined in:
- lib/duration_in_words/action_view/helpers/duration_helper.rb
Instance Method Summary collapse
-
#duration_in_words(duration, options = {}) ⇒ Object
Reports the Duration object as seconds.
Instance Method Details
#duration_in_words(duration, options = {}) ⇒ Object
Reports the Duration object as seconds.
Options
-
:format
- The format to be used in reporting the duration, :full or :compact (default: :compact) -
:locale
- IfI18n
is available, you can set a locale and use the connector options defined on the ‘support.array’ namespace in the corresponding dictionary file.
Examples
d = 1.day + 2.hours + 30.minutes duration_in_words(d) => 1d, 2h, and 30m d = 2.hours duration_in_words(d) => 2h
Using :format
option: d = 1.day + 2.hours + 30.minutes duration_in_words(d, format: :full) => 1 day, 2 hours, and 30 minutes
Using :locale
option:
# Given this locale dictionary:
#
# de:
# duration:
# in_words:
# format:
# compact:
# support:
# words_connector: ', '
# two_words_connector: ' und '
# last_word_connector: ', und '
# years:
# one: J
# other: ...
# months:
# ...
# full:
# ...
d = 1.day + 2.hours + 30.minutes duration_in_words(d, locale: :de) => 1 Tag, 2 Std., und 30 Sekunden
48 49 50 |
# File 'lib/duration_in_words/action_view/helpers/duration_helper.rb', line 48 def duration_in_words(duration, = {}) DurationInWords::Methods.duration_in_words(duration, ) end |