Module: Merb::Helpers::DateAndTime

Module | Merb::Helpers::DateAndTime
In: | lib/merb-helpers/date_time_helpers.rb

Provides a number of methods for displaying and dealing with dates and times

Parts were strongly based on ar-code.svn.engineyard.com/plugins/relative_time_helpers/, and active_support

The key methods are `relative_date`, `relative_date_span`, and `relative_time_span`. This also gives you the Rails style Time DSL for working with numbers eg. 3.months.ago or 5.days.until(1.year.from_now)

### Methods

prettier_time relative_date relative_date_span relative_time_span time_ago_in_words time_class time_lost_in_words time_output

### Public Class methods

time_class()
time_output(format, locale=nil)

#### Parameters

format<Symbol>: | time format to use
locale<String, Symbol>: | An optional value which can be used by localization plugins

#### Returns

String: | a string used to format time using strftime

### Public Instance methods

prettier_time(time, ampm=true, locale=nil)
relative_date(time, locale=nil)

Gives you a relative date in an attractive format

#### Parameters

time<~to_date>: | The Date or Time to test
locale<String, Symbol>: | An optional value which can be used by localization plugins

#### Returns

String: | Relative date

#### Examples

      relative_date(Time.now.utc) => "today"
      relative_date(5.days.ago) => "March 5th"
      relative_date(1.year.ago) => "March 10th, 2007"

relative_date_span(times)

Gives you a relative date span in an attractive format

#### Parameters

times<~first,~last>: | The Dates or Times to test

#### Returns

String: | The sexy relative date span

#### Examples

      relative_date([1.second.ago, 10.seconds.ago]) => "March 10th"
      relative_date([1.year.ago, 1.year.ago) => "March 10th, 2007"
      relative_date([Time.now, 1.day.from_now]) => "March 10th - 11th"
      relative_date([Time.now, 1.year.ago]) => "March 10th, 2007 - March 10th, 2008"

relative_time_span(times)

Gives you a relative date span in an attractive format

#### Parameters

times<~first,~last>: | The Dates or Times to test

#### Returns

String: | The sexy relative time span

#### Examples

      relative_time_span([1.second.ago, 10.seconds.ago]) => "12:00 - 12:09 AM March 10th"
      relative_time_span([1.year.ago, 1.year.ago) => "12:09 AM March 10th, 2007"
      relative_time_span([Time.now, 13.hours.from_now]) => "12:09 AM - 1:09 PM March 10th"
      relative_time_span([Time.now, 1.year.ago]) => "12:09 AM March 10th, 2007 - 12:09 AM March 10th, 2008"

time_ago_in_words(from_time, to_time = Time.now.utc, include_seconds = false, locale=nil)

Alias for time_lost_in_words

time_lost_in_words(from_time, to_time = Time.now.utc, include_seconds = false, locale=nil)

Condenses time… very similar to time_ago_in_words in ActionPack

#### Parameters

from_time<~to_time>: | The Date or Time to start from
to_time<~to_time>: | The Date or Time to go to, Defaults to Time.now.utc
include_seconds<Boolean>: | Count the seconds initially, Defaults to false
locale<String, Symbol>: | An optional value which can be used by localization plugins

#### Returns

String: | The time distance

#### Examples

time_lost_in_words(3.minutes.from_now) # => 3 minutes time_lost_in_words(Time.now - 15.hours) # => 15 hours time_lost_in_words(Time.now, 3.minutes.from_now) # => 3 minutes time_lost_in_words(Time.now) # => less than a minute time_lost_in_words(Time.now, Time.now, true) # => less than 5 seconds

[Validate]