Extended maintenance of Ruby versions 1.8.7 and 1.9.2 will end on July 31, 2014. Read more

In Files

  • xsd/datatypes.rb

Class/Module Index [+]

Quicksearch

XSD::XSDDateTimeImpl

Constants

SecInDay

Public Instance Methods

add_tz(s) click to toggle source
 
               # File xsd/datatypes.rb, line 582
def add_tz(s)
  s + of2tz(@data.offset)
end
            
of2tz(offset) click to toggle source
 
               # File xsd/datatypes.rb, line 551
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
            
screen_data(t) click to toggle source
 
               # File xsd/datatypes.rb, line 561
def screen_data(t)
  # convert t to a DateTime as an internal representation.
  if t.respond_to?(:to_datetime)      # 1.9 or later
    t.to_datetime
  elsif t.is_a?(DateTime)
    t
  elsif t.is_a?(Date)
    t = screen_data_str(t)
    t <<= 12 if t.year < 0
    t
  elsif t.is_a?(Time)
    jd = DateTime.civil_to_jd(t.year, t.mon, t.mday, DateTime::ITALY)
    fr = DateTime.time_to_day_fraction(t.hour, t.min, [t.sec, 59].min) +
      t.usec.to_r / 1000000 / SecInDay
    of = t.utc_offset.to_r / SecInDay
    DateTime.new0(DateTime.jd_to_ajd(jd, fr, of), of, DateTime::ITALY)
  else
    screen_data_str(t)
  end
end
            
to_date() click to toggle source
 
               # File xsd/datatypes.rb, line 526
def to_date
  Date.new0(@data.class.jd_to_ajd(@data.jd, 0, 0), 0, @data.start)
end
            
to_datetime() click to toggle source
 
               # File xsd/datatypes.rb, line 530
def to_datetime
  data
end
            
to_obj(klass) click to toggle source
 
               # File xsd/datatypes.rb, line 498
def to_obj(klass)
  if klass == Time
    to_time
  elsif klass == Date
    to_date
  elsif klass == DateTime
    to_datetime
  else
    nil
  end
end
            
to_time() click to toggle source
 
               # File xsd/datatypes.rb, line 510
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
            
tz2of(str) click to toggle source
 
               # File xsd/datatypes.rb, line 534
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
            

Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.

If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.

If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.

If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.

blog comments powered by Disqus