Class: Time
- Inherits:
-
Object
- Object
- Time
- Defined in:
- lib/time_utilities.rb
Overview
Class Method Summary collapse
Instance Method Summary collapse
- #add_days(days) ⇒ Object
- #on_date(date) ⇒ Object
-
#round(options = {}) ⇒ Object
default to whole minutes.
- #same_day?(date) ⇒ Boolean
Class Method Details
.parse(time) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/time_utilities.rb', line 8 def parse(time) # Chronic will usually return nil when unable to parse time # it throws an error, on 't' and a few other strings, so we # capture these here an assure that nil is returned begin chron = Chronic.parse time chron.round rescue Exception => e return nil end end |
Instance Method Details
#add_days(days) ⇒ Object
27 28 29 |
# File 'lib/time_utilities.rb', line 27 def add_days(days) t = self + days * 86400 # 24 * 60 * 60 end |
#on_date(date) ⇒ Object
31 32 33 34 |
# File 'lib/time_utilities.rb', line 31 def on_date(date) raise ArgumentError if ! date.kind_of? Time Time.new(date.year, date.month, date.day, self.hour, self.min, self.sec) end |
#round(options = {}) ⇒ Object
default to whole minutes
22 23 24 25 |
# File 'lib/time_utilities.rb', line 22 def round(={}) seconds = 60 Time.at((self.to_f / seconds).round * seconds) end |