Class: Time

Inherits:
Object
  • Object
show all
Defined in:
lib/vpim/time.rb

Overview

Extensions to builtin Time allowing addition to Time by multiples of other intervals than a second.

Instance Method Summary collapse

Instance Method Details

#plus_day(days) ⇒ Object

Returns a new Time, days later than this time. Does this do as I expect over DST? What if the hour doesn’t exist in the next day, due to DST changes?



35
36
37
38
39
# File 'lib/vpim/time.rb', line 35

def plus_day(days)
  d = Date.new(year, month, day)
  d += days
  Time.local(d.year, d.month, d.day, hour, min, sec, usec)
end

#plus_month(months) ⇒ Object

Returns a new Time, months later than this time. The day will be rounded down if it is not valid for that month. Jan 31 plus 1 month will be on Feb 28!



26
27
28
29
30
# File 'lib/vpim/time.rb', line 26

def plus_month(months)
  d = Date.new(year, month, day)
  d >>= months
  Time.local(d.year, d.month, d.day, hour, min, sec, usec)
end

#plus_year(years) ⇒ Object

Returns a new Time, years later than this time. Feb 29 of a leap year will be rounded up to Mar 1 if the target date is not a leap year.



19
20
21
# File 'lib/vpim/time.rb', line 19

def plus_year(years)
  Time.local(year + years, month, day, hour, min, sec, usec)
end