Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 8886

Show
Ignore:
Timestamp:
02/17/08 00:35:49 (7 months ago)
Author:
gbuesing
Message:

Adding TimeWithZone#between?

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activesupport/CHANGELOG

    r8885 r8886  
    11*SVN* 
     2 
     3* Adding TimeWithZone#between? [Geoff Buesing] 
    24 
    35* Time.=== returns true for TimeWithZone instances [Geoff Buesing] 
  • trunk/activesupport/lib/active_support/time_with_zone.rb

    r8884 r8886  
    124124    def <=>(other) 
    125125      utc <=> other 
     126    end 
     127     
     128    def between?(min, max) 
     129      utc.between?(min, max) 
    126130    end 
    127131     
     
    161165    alias_method :tv_sec, :to_i 
    162166   
    163     # A TimeProxy acts like a Time, so just return self 
     167    # A TimeWithZone acts like a Time, so just return self 
    164168    def to_time 
    165169      self 
  • trunk/activesupport/test/core_ext/time_with_zone_test.rb

    r8884 r8886  
    115115      assert_equal  0, @twz <=> ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 0, 0, 0), TimeZone['UTC'] ) 
    116116      assert_equal(-1, @twz <=> ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 0, 0, 1), TimeZone['UTC'] )) 
     117    end 
     118     
     119    def test_between? 
     120      assert @twz.between?(Time.utc(1999,12,31,23,59,59), Time.utc(2000,1,1,0,0,1)) 
     121      assert_equal false, @twz.between?(Time.utc(2000,1,1,0,0,1), Time.utc(2000,1,1,0,0,2)) 
    117122    end 
    118123