Sha256: 3c53e156046d43d9e3e24681507c0d6c2f10eb57f15e7793b42ec68efd525cf5

Contents?: true

Size: 938 Bytes

Versions: 1

Compression:

Stored size: 938 Bytes

Contents

module TimeCrisis::Support::Advance
  module Date
    def advance(options)
      options = options.dup
      d = self
      d = d >> options.delete(:years) * 12 if options[:years]
      d = d >> options.delete(:months) if options[:months]
      d = d + options.delete(:weeks) * 7 if options[:weeks]
      d = d + options.delete(:days) if options[:days]
      d
    end
  end

  module DateTime
    def advance(options)
      d = to_tc_date.advance(options)
      advanced_by_date = change(:year => d.year, :month => d.month, :day => d.day)
      seconds_to_advance = (options[:seconds] || 0) + (options[:minutes] || 0) * 60 + (options[:hours] || 0) * 3600
      seconds_to_advance == 0 ? advanced_by_date : (advanced_by_date + Rational(seconds_to_advance.round, 86400).to_f)
    end
  end
end

TimeCrisis::Date.send(:include, TimeCrisis::Support::Advance::Date)
TimeCrisis::DateTime.send(:include, TimeCrisis::Support::Advance::DateTime)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
time_crisis-0.1.4 lib/time_crisis/support/advance.rb