Sha256: 5fc8fc83ac1427fcac130abaa3b51fda44a4d8dbe8f9b203fd2c523ec260bd6d

Contents?: true

Size: 1.22 KB

Versions: 11

Compression:

Stored size: 1.22 KB

Contents

=begin
  Copyright (C) 2008 Sam Roberts

  This library is free software; you can redistribute it and/or modify it
  under the same terms as the ruby language itself, see the file COPYING for
  details.
=end

require 'date'

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

class Time
    # 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.
    def plus_year(years)
      Time.local(year + years, month, day, hour, min, sec, usec)
    end

    # 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!
    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

    # 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?
    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
end

Version data entries

11 entries across 11 versions & 6 rubygems

Version Path
xing-vpim-0.658.1 lib/vpim/time.rb
thoughtafter-vpim-0.7.0.1 lib/vpim/time.rb
scashin133-vpim-9.4.0 lib/vpim/time.rb
mumboe-vpim-0.7 lib/vpim/time.rb
mumboe-vpim-0.695 lib/vpim/time.rb
fairtilizer-vpim-0.695 lib/vpim/time.rb
vpim-0.602 lib/vpim/time.rb
vpim-0.619 lib/vpim/time.rb
vpim-0.658 lib/vpim/time.rb
vpim-0.695 lib/vpim/time.rb
vpim-0.604 lib/vpim/time.rb