Created
February 13, 2009 19:59
-
-
Save duien/64069 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Time | |
def aprox_eql? (time2, interval) | |
raise ArgumentError, 'Invalid Time object' unless time2.kind_of? Time | |
raise ArgumentError, 'Invalid interval' unless [:year, :month, :mon, :day, :hour, :min, :sec, :usec].include? interval | |
case interval | |
when :year | |
self.year == time2.year | |
when :month, :mon | |
self.year == time2.year and self.month == time2.month | |
when :day | |
self.year == time2.year and self.month == time2.month and self.day == time2.day | |
when :hour | |
self.year == time2.year and self.month == time2.month and self.day == time2.day and self.hour == time2.hour | |
when :min | |
self.year == time2.year and self.month == time2.month and self.day == time2.day and self.hour == time2.hour and self.min == time2.min | |
when :sec | |
self.year == time2.year and self.month == time2.month and self.day == time2.day and self.hour == time2.hour and self.min == time2.min and self.sec == time2.sec | |
when :usec | |
self == time2 | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment