Class: Time
Instance Method Summary collapse
-
#is_after?(other_time, leeway = 5) ⇒ Boolean
Method to compare self against other_time, returning true if self is equal to or later/after other_time This comparison is made with some leeway, so that if self is actually before other_time, but by less than the leeway amount (in seconds), the method will return true.
-
#is_before?(other_time, leeway = 5) ⇒ Boolean
Method to compare self against other_time, returning true if self is equal to or earlier/before other_time This comparison is made with some leeway, so that if self is actually after other_time, but by less than the leeway amount (in seconds), the method will return true.
-
#is_within?(other_time, leeway = 5) ⇒ Boolean
Method to compare self against other_time, returning true if it is close enough to self in either direction Leeway is in seconds.
-
#remove_subseconds ⇒ Object
Returns a new Time object with all subseconds set to zero.
Instance Method Details
#is_after?(other_time, leeway = 5) ⇒ Boolean
Method to compare self against other_time, returning true if self is equal to or later/after other_time This comparison is made with some leeway, so that if self is actually before other_time, but by less than the leeway amount (in seconds), the method will return true
21 22 23 24 |
# File 'lib/more_ruby/time.rb', line 21 def is_after?(other_time, leeway = 5) other_time -= leeway self >= other_time end |
#is_before?(other_time, leeway = 5) ⇒ Boolean
Method to compare self against other_time, returning true if self is equal to or earlier/before other_time This comparison is made with some leeway, so that if self is actually after other_time, but by less than the leeway amount (in seconds), the method will return true
13 14 15 16 |
# File 'lib/more_ruby/time.rb', line 13 def is_before?(other_time, leeway = 5) other_time += leeway self <= other_time end |
#is_within?(other_time, leeway = 5) ⇒ Boolean
Method to compare self against other_time, returning true if it is close enough to self in either direction Leeway is in seconds
28 29 30 |
# File 'lib/more_ruby/time.rb', line 28 def is_within?(other_time, leeway = 5) is_before?(other_time, leeway) && is_after?(other_time, leeway) end |
#remove_subseconds ⇒ Object
Returns a new Time object with all subseconds set to zero
5 6 7 8 |
# File 'lib/more_ruby/time.rb', line 5 def remove_subseconds ms = self.subsec self.clone - ms end |