TimeExtensions Plugin
November 13th, 2006
A minor plugin for all of you. This plugin merely adds two new methods to Time and Date:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
class TimeExtensionsTest < Test::Unit::TestCase def test_really_in_future assert 1.second.from_now.in_future? end def test_in_future_but_past assert !1.second.ago.in_future? end def test_really_in_past assert 1.second.ago.in_past? end def test_in_past_but_future assert !1.second.from_now.in_future? end end |
This makes for much more readable code:
1 2 3 4 5 |
if @post.published_at.in_future? then # do something else # do something else end |
1 2 3 |
$ script/plugin install \ svn://svn.teksol.info/svn/rails/plugins/time_extensions \ vendor/plugins/time_extensions |