# File lib/xsd/datatypes.rb, line 597 597: def add_tz(s) 598: s + of2tz(@data.offset) 599: end
# File lib/xsd/datatypes.rb, line 566 566: def of2tz(offset) 567: diffmin = offset * 24 * 60 568: if diffmin.zero? 569: 'Z' 570: else 571: ((diffmin < 0) ? '-' : '+') << format('%02d:%02d', 572: (diffmin.abs / 60.0).to_i, (diffmin.abs % 60.0).to_i) 573: end 574: end
# File lib/xsd/datatypes.rb, line 576 576: def screen_data(t) 577: # convert t to a DateTime as an internal representation. 578: if t.respond_to?(:to_datetime) # 1.9 or later 579: t.to_datetime 580: elsif t.is_a?(DateTime) 581: t 582: elsif t.is_a?(Date) 583: t = screen_data_str(t) 584: t <<= 12 if t.year < 0 585: t 586: elsif t.is_a?(Time) 587: jd = DateTime.civil_to_jd(t.year, t.mon, t.mday, DateTime::ITALY) 588: fr = DateTime.time_to_day_fraction(t.hour, t.min, [t.sec, 59].min) + 589: t.usec.to_r / DayInMicro 590: of = t.utc_offset.to_r / DayInSec 591: DateTime.new0(DateTime.jd_to_ajd(jd, fr, of), of, DateTime::ITALY) 592: else 593: screen_data_str(t) 594: end 595: end
# File lib/xsd/datatypes.rb, line 541 541: def to_date 542: Date.new0(@data.class.jd_to_ajd(@data.jd, 0, 0), 0, @data.start) 543: end
# File lib/xsd/datatypes.rb, line 545 545: def to_datetime 546: data 547: end
# File lib/xsd/datatypes.rb, line 513 513: def to_obj(klass) 514: if klass == Time 515: to_time 516: elsif klass == Date 517: to_date 518: elsif klass == DateTime 519: to_datetime 520: else 521: nil 522: end 523: end
# File lib/xsd/datatypes.rb, line 525 525: def to_time 526: begin 527: if @data.offset * DayInSec == Time.now.utc_offset 528: d = @data 529: usec = (d.sec_fraction * DayInMicro).round 530: Time.local(d.year, d.month, d.mday, d.hour, d.min, d.sec, usec) 531: else 532: d = @data.newof 533: usec = (d.sec_fraction * DayInMicro).round 534: Time.gm(d.year, d.month, d.mday, d.hour, d.min, d.sec, usec) 535: end 536: rescue ArgumentError 537: nil 538: end 539: end
# File lib/xsd/datatypes.rb, line 549 549: def tz2of(str) 550: /^(?:Z|(?:([+\-])(\d\d):(\d\d))?)$/ =~ str 551: sign = $1 552: hour = $2.to_i 553: min = $3.to_i 554: 555: of = case sign 556: when '+' 557: of = +(hour.to_r * 60 + min) / 1440 # 24 * 60 558: when '-' 559: of = -(hour.to_r * 60 + min) / 1440 # 24 * 60 560: else 561: 0 562: end 563: of 564: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.