A minor plugin for all of you. This plugin merely adds two new methods to Time and Date:

test/time_extensions_test.rb
 1 class TimeExtensionsTest < Test::Unit::TestCase
 2   def test_really_in_future
 3     assert 1.second.from_now.in_future?
 4   end
 5 
 6   def test_in_future_but_past
 7     assert !1.second.ago.in_future?
 8   end
 9 
10   def test_really_in_past
11     assert 1.second.ago.in_past?
12   end
13 
14   def test_in_past_but_future
15     assert !1.second.from_now.in_future?
16   end
17 end

This makes for much more readable code:

1 if @post.published_at.in_future? then
2   # do something
3 else
4   # do something else
5 end

Installation:

1 $ script/plugin install \
2   svn://svn.teksol.info/svn/rails/plugins/time_extensions \
3   vendor/plugins/time_extensions

Search

Your Host

A picture of me

I am François Beausoleil, a Ruby on Rails and Scala developer. During the day, I work on Seevibes, a platform to measure social interactions related to TV shows. At night, I am interested many things. Read my biography.

Top Tags

Books I read and recommend

Links

Projects I work on

Projects I worked on