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

Public Class methods

Public Instance methods

Gives you a relative date in an attractive format

Parameters

time<~to_date>:The Date or Time to test

Returns

String:The sexy relative date

Examples

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

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"

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)

Alias for time_lost_in_words

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

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]