Skip to content

Commit

Permalink
- Updated the docs
Browse files Browse the repository at this point in the history
- renamed only_latest_measure to highest_measure_only
  • Loading branch information
DBA committed Dec 29, 2010
1 parent 2fc02ab commit 54fc769
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
13 changes: 10 additions & 3 deletions README.markdown
Expand Up @@ -115,13 +115,20 @@ Using something other than ', and':
>> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.minute + 1.second, true, { :last_word_connector => ', finally ' })
=> "1 hour, 1 minute, finally 1 second"

#### :only\_latest\_measure
#### :highest\_measure\_only

Specify if you only want the latest measure item.
For times when Rails `distance_of_time_in_words` is not precise enough and `DOTIW` is too precise. For instance, if you only want to know the highest time part (measure) that elapsed between two dates.

>> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.minute + 1.second, true, { :only_latest_measure => true })
>> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.minute + 1.second, true, { :highest_measure_only => true })
=> "1 hour"

Notice how minutes and seconds were removed from the output. Another example:

>> distance_of_time_in_words(Time.now, Time.now + 1.minute + 1.second, true, { :highest_measure_only => true })
=> "1 minute"

Minutes are the highest measure, so seconds were discarded from the output.

## distance\_of\_time

If you have simply a number of seconds you can get the "stringified" version of this by using `distance_of_time`:
Expand Down
2 changes: 1 addition & 1 deletion lib/dotiw.rb
Expand Up @@ -60,7 +60,7 @@ def display_time_in_words(hash, include_seconds = false, options = {})

output = []

time_measurements = Hash[*time_measurements.first] if options.delete(:only_highest_measure)
time_measurements = Hash[*time_measurements.first] if options.delete(:highest_measure_only)

time_measurements.each do |measure, key|
name = options[:singularize] == :always || hash[key].between?(-1, 1) ? key.singularize : key
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/dotiw_spec.rb
Expand Up @@ -201,7 +201,7 @@
"1 year, 2 months, 3 days, 4 hours, and 6 seconds"],
[Time.now,
Time.now + 1.hour + 2.minutes + 3.seconds,
{ :only_highest_measure => true },
{ :highest_measure_only => true },
"1 hour"],
[Time.now,
Time.now + 2.year + 3.months + 4.days + 5.hours + 6.minutes + 7.seconds,
Expand Down

0 comments on commit 54fc769

Please sign in to comment.