提交 4a643f68 编写于 作者: G Geoff Buesing

Adding TimeWithZone#between?

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8886 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 25e139e5
*SVN* *SVN*
* Adding TimeWithZone#between? [Geoff Buesing]
* Time.=== returns true for TimeWithZone instances [Geoff Buesing] * Time.=== returns true for TimeWithZone instances [Geoff Buesing]
* TimeWithZone #+ and #- behave consistently with numeric arguments regardless of whether wrapped time is a Time or DateTime; consistenty answers false to #acts_like?(:date) [Geoff Buesing] * TimeWithZone #+ and #- behave consistently with numeric arguments regardless of whether wrapped time is a Time or DateTime; consistenty answers false to #acts_like?(:date) [Geoff Buesing]
......
...@@ -125,6 +125,10 @@ def <=>(other) ...@@ -125,6 +125,10 @@ def <=>(other)
utc <=> other utc <=> other
end end
def between?(min, max)
utc.between?(min, max)
end
def eql?(other) def eql?(other)
utc == other utc == other
end end
...@@ -160,7 +164,7 @@ def to_i ...@@ -160,7 +164,7 @@ def to_i
alias_method :hash, :to_i alias_method :hash, :to_i
alias_method :tv_sec, :to_i alias_method :tv_sec, :to_i
# A TimeProxy acts like a Time, so just return self # A TimeWithZone acts like a Time, so just return self
def to_time def to_time
self self
end end
......
...@@ -116,6 +116,11 @@ def test_compare_with_time_with_zone ...@@ -116,6 +116,11 @@ def test_compare_with_time_with_zone
assert_equal(-1, @twz <=> ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 0, 0, 1), TimeZone['UTC'] )) assert_equal(-1, @twz <=> ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 0, 0, 1), TimeZone['UTC'] ))
end end
def test_between?
assert @twz.between?(Time.utc(1999,12,31,23,59,59), Time.utc(2000,1,1,0,0,1))
assert_equal false, @twz.between?(Time.utc(2000,1,1,0,0,1), Time.utc(2000,1,1,0,0,2))
end
def test_eql? def test_eql?
assert @twz.eql?(Time.utc(2000)) assert @twz.eql?(Time.utc(2000))
assert @twz.eql?( ActiveSupport::TimeWithZone.new(Time.utc(2000), TimeZone["Hawaii"]) ) assert @twz.eql?( ActiveSupport::TimeWithZone.new(Time.utc(2000), TimeZone["Hawaii"]) )
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册