Module XSD::XSDDateTimeImpl
In: lib/xsd/datatypes.rb

Methods

add_tz   of2tz   screen_data   to_date   to_datetime   to_obj   to_time   tz2of  

Constants

SecInDay = 86400

Public Instance methods

[Source]

     # File lib/xsd/datatypes.rb, line 582
582:   def add_tz(s)
583:     s + of2tz(@data.offset)
584:   end

[Source]

     # File lib/xsd/datatypes.rb, line 551
551:   def of2tz(offset)
552:     diffmin = offset * 24 * 60
553:     if diffmin.zero?
554:       'Z'
555:     else
556:       ((diffmin < 0) ? '-' : '+') << format('%02d:%02d',
557:         (diffmin.abs / 60.0).to_i, (diffmin.abs % 60.0).to_i)
558:     end
559:   end

[Source]

     # File lib/xsd/datatypes.rb, line 561
561:   def screen_data(t)
562:     # convert t to a DateTime as an internal representation.
563:     if t.respond_to?(:to_datetime)      # 1.9 or later
564:       t.to_datetime
565:     elsif t.is_a?(DateTime)
566:       t
567:     elsif t.is_a?(Date)
568:       t = screen_data_str(t)
569:       t <<= 12 if t.year < 0
570:       t
571:     elsif t.is_a?(Time)
572:       jd = DateTime.civil_to_jd(t.year, t.mon, t.mday, DateTime::ITALY)
573:       fr = DateTime.time_to_day_fraction(t.hour, t.min, [t.sec, 59].min) +
574:         t.usec.to_r / 1000000 / SecInDay
575:       of = t.utc_offset.to_r / SecInDay
576:       DateTime.new0(DateTime.jd_to_ajd(jd, fr, of), of, DateTime::ITALY)
577:     else
578:       screen_data_str(t)
579:     end
580:   end

[Source]

     # File lib/xsd/datatypes.rb, line 526
526:   def to_date
527:     Date.new0(@data.class.jd_to_ajd(@data.jd, 0, 0), 0, @data.start)
528:   end

[Source]

     # File lib/xsd/datatypes.rb, line 530
530:   def to_datetime
531:     data
532:   end

[Source]

     # File lib/xsd/datatypes.rb, line 498
498:   def to_obj(klass)
499:     if klass == Time
500:       to_time
501:     elsif klass == Date
502:       to_date
503:     elsif klass == DateTime
504:       to_datetime
505:     else
506:       nil
507:     end
508:   end

[Source]

     # File lib/xsd/datatypes.rb, line 510
510:   def to_time
511:     begin
512:       if @data.offset * SecInDay == Time.now.utc_offset
513:         d = @data
514:         usec = (d.sec_fraction * SecInDay * 1000000).round
515:         Time.local(d.year, d.month, d.mday, d.hour, d.min, d.sec, usec)
516:       else
517:         d = @data.newof
518:         usec = (d.sec_fraction * SecInDay * 1000000).round
519:         Time.gm(d.year, d.month, d.mday, d.hour, d.min, d.sec, usec)
520:       end
521:     rescue ArgumentError
522:       nil
523:     end
524:   end

[Source]

     # File lib/xsd/datatypes.rb, line 534
534:   def tz2of(str)
535:     /^(?:Z|(?:([+\-])(\d\d):(\d\d))?)$/ =~ str
536:     sign = $1
537:     hour = $2.to_i
538:     min = $3.to_i
539: 
540:     of = case sign
541:       when '+'
542:         of = +(hour.to_r * 60 + min) / 1440    # 24 * 60
543:       when '-'
544:         of = -(hour.to_r * 60 + min) / 1440    # 24 * 60
545:       else
546:         0
547:       end
548:     of
549:   end

[Validate]