Time Comparisons plugin
Plugin details
Documentation
Install the plugin:
ruby script/plugin install http://time-comparisons.googlecode.com/svn/trunk/
Examples:
past = Time.utc(2007, 6, 7, 4, 30, 29) present = Time.utc(2007, 6, 7, 4, 30, 30) future = Time.utc(2007, 6, 7, 4, 30, 31) present.same_time? DateTime.civil(2007, 6, 7, 4, 30, 30) # => true past.before? present # => true past.same_time_or_before? present # => true past.after? present # => false past.after? Date.new(2012,1,1) # => true past.same_time_or_after? present # => false present.within? past, future # => true present.outside? past, future # => false times = [present, future, past, Date.new(1990), DateTime.civil(2012)] puts times.sort {|a,b| a.compare_time(b)} # => =begin 1990-01-01 Fri Jun 08 16:30:29 UTC 2007 Fri Jun 08 16:30:30 UTC 2007 Fri Jun 08 16:30:31 UTC 2007 2012-01-01T00:00:00+00:00 =end
Note that Date objects are considered as a time point at the beginning of the day. Therefore the following will be true:
Time.now.after? Date.today # => true
Further Documentation
There is currently no advanced documentation for this plugin.
New documentationEdit plugin | Back in time (1 older version) | Last edited by: hardway, 8 months ago

