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
Installation:
1
2
3
$ script/plugin install \
  svn://svn.teksol.info/svn/rails/plugins/time_extensions \
  vendor/plugins/time_extensions

 

Search

A picture of me

I am François Beausoleil, a Ruby on Rails coder. During the day, I work on XLsuite. At night, I am interested many things. Read my biography

Tags

(3) (1) (0) (2) (1) (1) (2) (2) (1) (2) (1) (2) (1) (2) (1) (1) (1) (1) (2) (14) (1) (1) (1) (1) (2) (1) (1) (2) (0) (1) (2) (1) (3) (1) (1) (1) (1) (1) (1) (0) (3) (2) (1) (2) (2) (1) (3) (2) (8) (8) (9) (12) (1) (1) (3) (1) (1) (1) (1) (1) (1) (2) (2) (2) (1) (1) (3) (1) (3) (1) (0) (23) (1) (1) (0) (1) (1) (1) (23) (25) (1) (1) (13) (1) (1) (2) (3) (1) (1) (4) (1) (2) (3) (0) (1) (7) (3) (1) (5) (5) (2) (2) (2) (4) (6) (7) (1) (0) (1) (1) (2) (2) (1) (4) (12) (2) (1) (2) (4) (1) (1) (1) (2) (8) (2) (3) (2) (2) (1) (3) (1) (1)

Links

Projects I work on

Categories

Archives