summaryrefslogtreecommitdiff
path: root/lib/date.rb
diff options
context:
space:
mode:
authortadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-08-16 23:35:28 +0000
committertadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-08-16 23:35:28 +0000
commitae3a58e8c53a8966f3bcc53395878593e137e3bf (patch)
treea5ae158de44af4ff1a2727908fb994d773228b0b /lib/date.rb
parentcfed2cefb2de1762b50c8345b5048246d7cd7c7f (diff)
* lib/date/delta.rb: merged from date4. [experimental]
* lib/date/delta/parser.*: ditto. * lib/date.rb: followed the above changes. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24567 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/date.rb')
-rw-r--r--lib/date.rb18
1 files changed, 17 insertions, 1 deletions
diff --git a/lib/date.rb b/lib/date.rb
index f3edb5374b..802ce8ec14 100644
--- a/lib/date.rb
+++ b/lib/date.rb
@@ -194,6 +194,7 @@
# puts secs_to_new_year()
require 'date/format'
+require 'date/delta'
# Class representing a date.
#
@@ -1336,6 +1337,9 @@ class Date
def + (n)
case n
when Numeric; return self.class.new!(@ajd + n, @of, @sg)
+ when Delta
+ d = n.__send__(:delta)
+ return (self >> d.imag) + d.real
end
raise TypeError, 'expected numeric'
end
@@ -1352,8 +1356,11 @@ class Date
case x
when Numeric; return self.class.new!(@ajd - x, @of, @sg)
when Date; return @ajd - x.ajd
+ when Delta
+ d = x.__send__(:delta)
+ return (self << d.imag) - d.real
end
- raise TypeError, 'expected numeric or date'
+ raise TypeError, 'expected numeric'
end
# Compare this date with another date.
@@ -1371,6 +1378,12 @@ class Date
case other
when Numeric; return @ajd <=> other
when Date; return @ajd <=> other.ajd
+ else
+ begin
+ l, r = other.coerce(self)
+ return l <=> r
+ rescue NoMethodError
+ end
end
nil
end
@@ -1385,6 +1398,9 @@ class Date
case other
when Numeric; return jd == other
when Date; return jd == other.jd
+ else
+ l, r = other.coerce(self)
+ return l === r
end
false
end