Method: Datte::Dattetime#after
- Defined in:
- lib/datte/dattetime.rb
#after(md) ⇒ Object
何年後、何ヶ月後、何日後, 何時間後, 何分後
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/datte/dattetime.rb', line 37 def after(md) if md.matched?(:year) @year, @month, @day = now[:year] + md[:year].to_i, now[:month], now[:day] end if md.matched?(:month) carry = (now[:month] + md[:month].to_i) / 12 @year, @month, @day = now[:year] + carry, now[:month] + md[:month].to_i , now[:day] end if md.matched?(:day) days = [31,28,31,30,31,30,31,31,30,31,30,31][now[:month] - 1] carry = (now[:day] + md[:day].to_i) / days @year, @month, @day = now[:year], now[:month] + carry, now[:day] + md[:day].to_i - carry * days end if md.matched?(:hour) carry = (now[:hour] + md[:hour].to_i) / 24 @day, @hour = now[:day] + carry, now[:hour] + md[:hour].to_i - carry * 24, now[:min] end # @date >> (md[:year].to_i * 12) if md.matched?(:year) # 何年後 # @date >> md[:month].to_i if md.matched?(:month) # 何ヶ月後 # @date + md[:day].to_i if md.matched?(:day) # 何日後 # @date + Rational(md[:hour].to_i, 24) if md.matched?(:hour) # 何時間後 # @date + Rational(md[:hour].to_i, 24 * 60) if md.matched?(:hour) # 何分後 end |