diff options
author | nahi <nahi@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-11-28 05:53:16 +0000 |
---|---|---|
committer | nahi <nahi@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-11-28 05:53:16 +0000 |
commit | 42bca643c3ec41782d519c7676383f8f71e67a7a (patch) | |
tree | 3ddde51774247d839f4e12ae0d9af6ff2e84d35b /lib/xsd | |
parent | a017b0cc8aea236600d47ff04cd829f84499f414 (diff) |
* lib/soap/streamHandler.rb: drop unused http parameters.
* lib/soap/encodingstyle/soapHandler.rb, lib/soap/mapping/factory.rb,
lib/soap/mapping/mapping.rb, lib/soap/mapping/registry.rb,
lib/wsdl/soap/complexType.rb: ApacheSOAP's map support was broken under WSDL
dynanic client environment. fixed.
* test/wsdl/raa/*: add tests.
* lib/xsd/datatypes.rb: dateTime precision bug fix (at least, I hope.) bug of
soap4r. XSDDateTimeImple.to_time passed a Float to Time.local/Time.gm as an
usec, and NUM2LONG(rb_num2long for Float) causes rounding error.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5045 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/xsd')
-rw-r--r-- | lib/xsd/datatypes.rb | 60 |
1 files changed, 48 insertions, 12 deletions
diff --git a/lib/xsd/datatypes.rb b/lib/xsd/datatypes.rb index ca4ef15576..f318e612b1 100644 --- a/lib/xsd/datatypes.rb +++ b/lib/xsd/datatypes.rb @@ -162,7 +162,6 @@ class XSDString < XSDAnySimpleType def initialize(value = nil) super() @type = Type - @encoding = nil set(value) if value end @@ -254,6 +253,7 @@ private end @data = _to_s + @data.freeze end # 0.0 -> 0; right? @@ -440,6 +440,7 @@ private @min = $7.to_i @sec = $8 ? XSDDecimal.new($8) : 0 @data = _to_s + @data.freeze end def _to_s @@ -476,11 +477,11 @@ module XSDDateTimeImpl begin if @data.offset * SecInDay == Time.now.utc_offset d = @data - usec = (d.sec_fraction * SecInDay * 1000000).to_f + 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).to_f + 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 @@ -516,6 +517,7 @@ module XSDDateTimeImpl end def _set(t) + set_datetime_init(t) if (t.is_a?(Date)) @data = t elsif (t.is_a?(Time)) @@ -541,11 +543,16 @@ class XSDDateTime < XSDAnySimpleType def initialize(value = nil) super() @type = Type + @secfrac = nil set(value) if value end private + def set_datetime_init(t) + @secfrac = nil + end + def set_str(t) /^([+\-]?\d{4,})-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d(?:\.(\d*))?)(Z|(?:[+\-]\d\d:\d\d)?)?$/ =~ t.to_s.strip unless Regexp.last_match @@ -568,6 +575,7 @@ private zonestr = $8 @data = DateTime.civil(year, mon, mday, hour, min, sec, tz2of(zonestr)) + @secfrac = secfrac if secfrac diffday = secfrac.to_i.to_r / (10 ** secfrac.size) / SecInDay @@ -588,10 +596,11 @@ private s = format('%.4d-%02d-%02dT%02d:%02d:%02d', year, @data.mon, @data.mday, @data.hour, @data.min, @data.sec) if @data.sec_fraction.nonzero? - fr = @data.sec_fraction * SecInDay - shiftsize = fr.denominator.to_s.size + 1 - fr_s = (fr * (10 ** shiftsize)).to_i.to_s - s << '.' << '0' * (shiftsize - fr_s.size) << fr_s.sub(/0+$/, '') + if @secfrac + s << ".#{ @secfrac }" + else + s << sprintf("%.16f", (@data.sec_fraction * SecInDay).to_f).sub(/^0/, '').sub(/0*$/, '') + end end add_tz(s) end @@ -604,11 +613,16 @@ class XSDTime < XSDAnySimpleType def initialize(value = nil) super() @type = Type + @secfrac = nil set(value) if value end private + def set_datetime_init(t) + @secfrac = nil + end + def set_str(t) /^(\d\d):(\d\d):(\d\d(?:\.(\d*))?)(Z|(?:([+\-])(\d\d):(\d\d))?)?$/ =~ t.to_s.strip unless Regexp.last_match @@ -622,19 +636,22 @@ private zonestr = $5 @data = DateTime.civil(1, 1, 1, hour, min, sec, tz2of(zonestr)) + @secfrac = secfrac if secfrac - @data += secfrac.to_i.to_r / (10 ** secfrac.size) / SecInDay + diffday = secfrac.to_i.to_r / (10 ** secfrac.size) / SecInDay + @data += diffday end end def _to_s s = format('%02d:%02d:%02d', @data.hour, @data.min, @data.sec) if @data.sec_fraction.nonzero? - fr = @data.sec_fraction * SecInDay - shiftsize = fr.denominator.to_s.size + 1 - fr_s = (fr * (10 ** shiftsize)).to_i.to_s - s << '.' << '0' * (shiftsize - fr_s.size) << fr_s.sub(/0+$/, '') + if @secfrac + s << ".#{ @secfrac }" + else + s << sprintf("%.16f", (@data.sec_fraction * SecInDay).to_f).sub(/^0/, '').sub(/0*$/, '') + end end add_tz(s) end @@ -652,6 +669,9 @@ class XSDDate < XSDAnySimpleType private + def set_datetime_init(t) + end + def set_str(t) /^([+\-]?\d{4,})-(\d\d)-(\d\d)(Z|(?:([+\-])(\d\d):(\d\d))?)?$/ =~ t.to_s.strip unless Regexp.last_match @@ -688,6 +708,9 @@ class XSDGYearMonth < XSDAnySimpleType private + def set_datetime_init(t) + end + def set_str(t) /^([+\-]?\d{4,})-(\d\d)(Z|(?:([+\-])(\d\d):(\d\d))?)?$/ =~ t.to_s.strip unless Regexp.last_match @@ -723,6 +746,9 @@ class XSDGYear < XSDAnySimpleType private + def set_datetime_init(t) + end + def set_str(t) /^([+\-]?\d{4,})(Z|(?:([+\-])(\d\d):(\d\d))?)?$/ =~ t.to_s.strip unless Regexp.last_match @@ -757,6 +783,9 @@ class XSDGMonthDay < XSDAnySimpleType private + def set_datetime_init(t) + end + def set_str(t) /^(\d\d)-(\d\d)(Z|(?:[+\-]\d\d:\d\d)?)?$/ =~ t.to_s.strip unless Regexp.last_match @@ -788,6 +817,9 @@ class XSDGDay < XSDAnySimpleType private + def set_datetime_init(t) + end + def set_str(t) /^(\d\d)(Z|(?:[+\-]\d\d:\d\d)?)?$/ =~ t.to_s.strip unless Regexp.last_match @@ -818,6 +850,9 @@ class XSDGMonth < XSDAnySimpleType private + def set_datetime_init(t) + end + def set_str(t) /^(\d\d)(Z|(?:[+\-]\d\d:\d\d)?)?$/ =~ t.to_s.strip unless Regexp.last_match @@ -935,6 +970,7 @@ private @prefix = $1 @localpart = $2 @data = _to_s + @data.freeze end def _to_s |