Sha256: fcf2050a05b4f8668283fe1fc4e1282338ebce73e1e2cd12d195738088da468f

Contents?: true

Size: 660 Bytes

Versions: 2

Compression:

Stored size: 660 Bytes

Contents

class ISO8601::DateTime < ::DateTime

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

  def to_iso8601_date
    ISO8601::Date.new year, month, day
  end

  def to_iso8601_time
    ISO8601::Time.new hour, minute, second, zone
  end

  def +(other)
    case other
    when ISO8601::Duration
      date = to_iso8601_date + other
      time = to_iso8601_time + other
      date + time
    else super end
  end

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

Version data entries

2 entries across 2 versions & 1 rubygems

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