Days and times plugin

Plugin details


Enhances Rails' core-extensions relating to Time. Introduces the idea of a TimeSpan and an AnchoredTimeSpan. Try something like Now.until(Tomorrow), or 3.hours.starting(15.minutes.from_now).

1.hour has been changed to mean what it should: a span of time lasting one hour. That span of time can be attached to a start_time and become an AnchoredTimeSpan, or it can be mathematically manipulated just like you would think of a time span. 1.hour / 30.minutes will return 2, and 1.hour / 2 will return 30.minutes.

Websitehttp://blog.behindlogic.com/ Repositoryhttp://svn.behindlogic.com/public/rails/plugins/days_and_times/ Author dcparker Tags Date LicenseMIT

Documentation

Install the plugin:
ruby script/plugin install http://svn.behindlogic.com/public/rails/plugins/days_and_times/

Example code

>> 1.second
=> #

>> 1.minute 
=> #

>> 1.hour
=> #

>> 1.day
=> #

>> 1.week
=> #

>> 1.week - 6.days
=> #

>> 2.days / 2
=> #

>> 2.weeks / 2.days
=> 7

>> 1.week * 2
=> #

>> 1.day * 7
=> #

>> 1.day.from_now
=> Tue Aug 07 16:59:28 -0400 2007

>> 1.day.from(Now)
=> Tue Aug 07 16:58:19 -0400 2007

>> 2.days.from(Yesterday) == Tomorrow
=> true

>> 1.minute.from(Now).until(Tomorrow)
=> #

>> 2.hours.starting(Now) 
=> #

>> 2.hours.starting(Now).length / 1.hour
=> 2

>> 2.hours.starting(Now).end_time
=> Mon Aug 06 18:58:19 -0400 2007

>> 1.day.starting(1.week.from(Today))            
=> #

>> 1.day.starting(1.week.from(Today)).day_name
=> "Monday"

Further Documentation

There is currently no advanced documentation for this plugin.

New documentation

Edit plugin | Back in time (3 older versions) | Last edited by: Guest, 3 months ago