2017-01-26 19:29:21 -05:00
|
|
|
# frozen_string_literal: true
|
2011-05-21 08:25:03 -04:00
|
|
|
# date.rb: Written by Tadayoshi Funaba 1998-2011
|
2002-05-18 08:41:51 -04:00
|
|
|
|
2011-05-21 08:25:03 -04:00
|
|
|
require 'date_core'
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
class Date
|
2021-11-18 04:18:33 -05:00
|
|
|
VERSION = '3.2.2' # :nodoc:
|
2000-07-18 03:37:02 -04:00
|
|
|
|
2019-08-25 13:01:13 -04:00
|
|
|
def infinite?
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2006-08-25 19:09:30 -04:00
|
|
|
class Infinity < Numeric # :nodoc:
|
|
|
|
|
|
|
|
def initialize(d=1) @d = d <=> 0 end
|
|
|
|
|
|
|
|
def d() @d end
|
|
|
|
|
|
|
|
protected :d
|
|
|
|
|
2016-11-29 05:47:43 -05:00
|
|
|
def zero?() false end
|
|
|
|
def finite?() false end
|
|
|
|
def infinite?() d.nonzero? end
|
|
|
|
def nan?() d.zero? end
|
2006-08-25 19:09:30 -04:00
|
|
|
|
|
|
|
def abs() self.class.new end
|
|
|
|
|
2016-11-29 05:47:43 -05:00
|
|
|
def -@() self.class.new(-d) end
|
|
|
|
def +@() self.class.new(+d) end
|
2006-08-25 19:09:30 -04:00
|
|
|
|
2016-11-29 05:47:43 -05:00
|
|
|
def <=>(other)
|
2006-08-25 19:09:30 -04:00
|
|
|
case other
|
2008-01-17 07:05:43 -05:00
|
|
|
when Infinity; return d <=> other.d
|
2021-06-15 13:39:42 -04:00
|
|
|
when Float::INFINITY; return d <=> 1
|
|
|
|
when -Float::INFINITY; return d <=> -1
|
2008-01-17 07:05:43 -05:00
|
|
|
when Numeric; return d
|
2006-08-25 19:09:30 -04:00
|
|
|
else
|
2014-10-13 16:16:07 -04:00
|
|
|
begin
|
|
|
|
l, r = other.coerce(self)
|
|
|
|
return l <=> r
|
|
|
|
rescue NoMethodError
|
|
|
|
end
|
2006-08-25 19:09:30 -04:00
|
|
|
end
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def coerce(other)
|
|
|
|
case other
|
|
|
|
when Numeric; return -d, d
|
|
|
|
else
|
2014-10-13 16:16:07 -04:00
|
|
|
super
|
2006-08-25 19:09:30 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-03-07 03:44:45 -05:00
|
|
|
def to_f
|
|
|
|
return 0 if @d == 0
|
|
|
|
if @d > 0
|
2014-10-13 16:16:07 -04:00
|
|
|
Float::INFINITY
|
2011-03-07 03:44:45 -05:00
|
|
|
else
|
2014-10-13 16:16:07 -04:00
|
|
|
-Float::INFINITY
|
2011-03-07 03:44:45 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2006-08-25 19:09:30 -04:00
|
|
|
end
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
end
|