Skip to content

Instantly share code, notes, and snippets.

@duien
Created February 13, 2009 19:59
Show Gist options
  • Save duien/64069 to your computer and use it in GitHub Desktop.
Save duien/64069 to your computer and use it in GitHub Desktop.
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