XSD::XSDDateTimeImpl (Module)

In: xsd/datatypes.rb

Methods

_set   add_tz   of2tz   to_time   tz2of  

Constants

SecInDay = 86400

Public Instance methods

[Source]

# File xsd/datatypes.rb, line 527
  def _set(t)
    set_datetime_init(t)
    if (t.is_a?(Date))
      @data = t
    elsif (t.is_a?(Time))
      sec, min, hour, mday, month, year = t.to_a[0..5]
      diffday = t.usec.to_r / 1000000 / SecInDay
      of = t.utc_offset.to_r / SecInDay
      @data = DateTime.civil(year, month, mday, hour, min, sec, of)
      @data += diffday
    else
      set_str(t)
    end
  end

[Source]

# File xsd/datatypes.rb, line 542
  def add_tz(s)
    s + of2tz(@data.offset)
  end

[Source]

# File xsd/datatypes.rb, line 517
  def of2tz(offset)
    diffmin = offset * 24 * 60
    if diffmin.zero?
      'Z'
    else
      ((diffmin < 0) ? '-' : '+') << format('%02d:%02d',
        (diffmin.abs / 60.0).to_i, (diffmin.abs % 60.0).to_i)
    end
  end

[Source]

# File xsd/datatypes.rb, line 484
  def to_time
    begin
      if @data.offset * SecInDay == Time.now.utc_offset
        d = @data
        usec = (d.sec_fraction * SecInDay * 1000000).round
        Time.local(d.year, d.month, d.mday, d.hour, d.min, d.sec, usec)
      else
        d = @data.newof
        usec = (d.sec_fraction * SecInDay * 1000000).round
        Time.gm(d.year, d.month, d.mday, d.hour, d.min, d.sec, usec)
      end
    rescue ArgumentError
      nil
    end
  end

[Source]

# File xsd/datatypes.rb, line 500
  def tz2of(str)
    /^(?:Z|(?:([+\-])(\d\d):(\d\d))?)$/ =~ str
    sign = $1
    hour = $2.to_i
    min = $3.to_i

    of = case sign
      when '+'
        of = +(hour.to_r * 60 + min) / 1440    # 24 * 60

      when '-'
        of = -(hour.to_r * 60 + min) / 1440    # 24 * 60

      else
        0
      end
    of
  end

[Validate]