Sha256: f9246ff87f124cb3646684cfed6c8db0ce2830837475e303635654a2754445fa
Contents?: true
Size: 1.2 KB
Versions: 4
Compression:
Stored size: 1.2 KB
Contents
# This file is part of the "Utopia Framework" project, and is released under the MIT license. # Copyright 2010 Samuel Williams. All rights reserved. # See <utopia.rb> for licensing details. # These amendments allow for Date <=> DateTime <=> Time, and so on. # Use only if required. This implementation works for Ruby 1.9.2. require 'date' class Date alias_method :old_compare, :<=> def <=>(other) if other.class == Date old_compare(other) else if Time === other other = other.to_datetime end if DateTime === other result = old_compare(other.to_date) if result == 0 && other.day_fraction > 0 -1 else result end end end end end class Time alias_method :old_compare, :<=> def <=>(other) if other.class == Date (other <=> self) * -1 elsif Time === other old_compare(other) else if DateTime === other other = other.to_time end old_compare(other) end end end class DateTime alias_method :old_compare, :<=> def <=>(other) if other.class == Date (other <=> self) * -1 elsif DateTime === other old_compare(other) else if Time === other other = other.to_datetime end old_compare(other) end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
utopia-0.10.0 | lib/utopia/extensions/date.rb |
utopia-0.9.61 | lib/utopia/extensions/date.rb |
utopia-0.9.60 | lib/utopia/extensions/date.rb |
utopia-0.9.59 | lib/utopia/extensions/date.rb |