Technical
Time Calculations

Cob ( Close Of Business ) Date

Hey, we can still have fun even with such big words.

Link to API with more of that kind of toys


bus_day = Time.local(2007,3,30)
Fri Mar 30 00:00:00 -0400 2007
bus_day.advance(:days => 3)
Mon Apr 02 00:00:00 -0400 2007
#We found a bug that was giving us mar 33 :)

Today? method


#Test First

def test_today?
  current_date = Date.new(2007,4,20)
  assert(current_date.today?)
  assert(!Date.new(2007,4,18).today?)
end

class Date
 def today?
     if self == Time.now.to_date
      return true
     else
      return false
    end
  end
end

How to compare time ignoring seconds.

This one does not directly relates to ActiveSupport , but I thought I put it here since its still relates to Time class.


>> time1,time2 = Time.now,Time.now
=> [Mon Jun 18 10:09:14 -0400 2007, Mon Jun 18 10:09:14 -0400 2007]
>> time1.to_i / 60 > time2.to_i / 60
=> false
>> time1.to_i / 60 == time2.to_i / 60
=> true