Sha256: f4c7e5ee7a912e4e37ab12cb0bac6199c63c5456cda6e432b9d13124ed8b7dc3

Contents?: true

Size: 670 Bytes

Versions: 2

Compression:

Stored size: 670 Bytes

Contents

class ISO8601::Date < ::Date

  def self.new(*args)
    case value = args[0]
    when Numeric then super
    when String
      dt = ::Date.iso8601 value
      super dt.year, dt.month, dt.day
    else super end
  end

  def +(other)
    case other
    when ISO8601::Time
      ISO8601::DateTime.new year, month, day,
        other.hour, other.minute, other.second, other.zone
    when ISO8601::Duration
      { years: [:>>, 12], months: [:>>, 1], weeks: [:+, 7], days: [:+, 1] }.reduce self do |date, (key, (action, factor))|
        date.send action, other.to_h[key] * factor
      end
    else super end
  end

  def inspect
    "#<ISO8601::Date: #{iso8601}>"
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
iso8601-basic-0.1.1 lib/iso8601/date.rb
iso8601-basic-0.1.0 lib/iso8601/date.rb