Module: ActionView::Helpers::DurationHelper
- Includes:
- DurationInWords::Methods
- Defined in:
- lib/duration_in_words/action_view/helpers/duration_helper.rb,
sig/duration_in_words.rbs
Constant Summary
Constants included from DurationInWords::Methods
DurationInWords::Methods::VALID_FORMATS
Instance Method Summary collapse
-
#duration_in_words(duration, options = {}) ⇒ String
Reports the Duration object as seconds.
Methods included from DurationInWords::Methods
#normalize_format, #parse_options, #raise_type_error, #sentence_options, #sentencify
Instance Method Details
#duration_in_words(duration, options = {}) ⇒ String
Reports the Duration object as seconds.
Options
- :format - The format to be used in reporting the duration, :full or :compact (default: :compact)
- :locale - Defaults to the current
I18n.locale. You can also pass a locale explicitly 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 |