Rails :: New date calculations - Changeset 6937

Posted by Ken Brooks Mon, 04 Jun 2007 21:18:00 GMT

Seems like a flurry of just bugfixes in edge rails lately. Mixed in today was a few additions. The ActiveSupport::CoreExtensions::Date:Calculations had since, ago, beginning_of_day, end_of_day added.

Here are the tests so you can see some of the basic usage.

def test_since 
  assert_equal Time.local(2005,2,21,0,0,45), Date.new(2005,2,21).since(45) 
end 

def test_ago 
  assert_equal Time.local(2005,2,20,23,59,15), Date.new(2005,2,21).ago(45) 
end 

def test_beginning_of_day 
  assert_equal Time.local(2005,2,21,0,0,0), Date.new(2005,2,21).beginning_of_day 
end 

def test_end_of_day 
  assert_equal Time.local(2005,2,21,23,59,59), Date.new(2005,2,21).end_of_day 
end 

beginningof_day and endof_day make sense, they give you the beginning of the date you are operating on. not so sure since and ago read correctly.

no comments

Comments

(leave url/email »)

   Comment Markup Help Preview comment