Skip to content
This repository has been archived by the owner on Jun 24, 2022. It is now read-only.

Commit

Permalink
Add Date::Infinity implementation, bump version to 1.0.9 (Fixes #50)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyevans committed Mar 19, 2013
1 parent f3c1416 commit b0fcad6
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG
@@ -1,3 +1,7 @@
=== 1.0.9 (2013-03-19)

* Add Date::Infinity implementation (jeremyevans) (#50)

=== 1.0.8 (2013-02-28)

* Switch %i to %d in format strings to work on ruby 2.0 (jeremyevans)
Expand Down
2 changes: 1 addition & 1 deletion home_run.gemspec
@@ -1,6 +1,6 @@
HOME_RUN_GEMSPEC = Gem::Specification.new do |s|
s.name = 'home_run'
s.version = '1.0.8'
s.version = '1.0.9'
s.platform = Gem::Platform::RUBY
s.has_rdoc = true
s.extra_rdoc_files = ["README.rdoc", "CHANGELOG", "LICENSE"]
Expand Down
55 changes: 55 additions & 0 deletions lib/date.rb
Expand Up @@ -4,4 +4,59 @@
raise unless RUBY_PLATFORM =~ /mswin|mingw/
require "#{RUBY_VERSION[0...3]}/date_ext"
end

class Date
class Infinity < Numeric # :nodoc:

include Comparable

def initialize(d=1) @d = d <=> 0 end

def d() @d end

protected :d

def zero? () false end
def finite? () false end
def infinite? () d.nonzero? end
def nan? () d.zero? end

def abs() self.class.new end

def -@ () self.class.new(-d) end
def +@ () self.class.new(+d) end

def <=> (other)
case other
when Infinity; return d <=> other.d
when Numeric; return d
else
begin
l, r = other.coerce(self)
return l <=> r
rescue NoMethodError
end
end
nil
end

def coerce(other)
case other
when Numeric; return -d, d
else
super
end
end

def to_f
return 0 if @d == 0
if @d > 0
Float::INFINITY
else
-Float::INFINITY
end
end
end
end

require "date/format" unless defined?(Date::Format::ZONES)

0 comments on commit b0fcad6

Please sign in to comment.