Class: Date

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_com/core_ext/date.rb

Instance Method Summary collapse

Instance Method Details

#after(other) ⇒ Object

‘2018-01-01’.to_date.after(2.month) => ‘2018-02-31’ ‘2018-01-31’.to_date.after(1.month) => ‘2018-03-02’



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/rails_com/core_ext/date.rb', line 5

def after(other)
  if ActiveSupport::Duration === other
    if other.parts.keys == [:months]
      date = self + other
      if date.day == self.day
        r = date - 1.day
      else
        r = date + (self.day - date.day - 1).days
      end

      r
    else
      self + other
    end
  else
    self + other
  end
end