diff options
author | kou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-03-21 09:54:07 +0000 |
---|---|---|
committer | kou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-03-21 09:54:07 +0000 |
commit | cfbe158faea79c6c61f04e99d1309e26bf9f1e54 (patch) | |
tree | 93e7e4141f9931e618810e14410aabd6c54bcc03 | |
parent | 7ead69e5b3a2b09878037f11a7dda59ae402ccbf (diff) | |
download | ruby-cfbe158faea79c6c61f04e99d1309e26bf9f1e54.tar.gz |
* lib/rss/{rss,dublincore,syndication}.rb: handled W3CDTF correctly.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5990 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | lib/rss/dublincore.rb | 2 | ||||
-rw-r--r-- | lib/rss/rss.rb | 38 | ||||
-rw-r--r-- | lib/rss/syndication.rb | 2 |
4 files changed, 42 insertions, 4 deletions
@@ -1,3 +1,7 @@ +Sun Mar 21 18:48:20 2004 Kouhei Sutou <kou@cozmixng.org> + + * lib/rss/{rss,dublincore,syndication}.rb: handled W3CDTF correctly. + Sun Mar 21 18:15:29 2004 Kouhei Sutou <kou@cozmixng.org> * test/rss/test_xml-stylesheet.rb: added tests for xml-stylesheet. diff --git a/lib/rss/dublincore.rb b/lib/rss/dublincore.rb index 4b5daf5076..dcf8e46c65 100644 --- a/lib/rss/dublincore.rb +++ b/lib/rss/dublincore.rb @@ -22,7 +22,7 @@ module RSS end %w(date).each do |x| - install_date_element("\#{DC_PREFIX}_\#{x}", 'iso8601', x) + install_date_element("\#{DC_PREFIX}_\#{x}", 'w3cdtf', x) end EOC end diff --git a/lib/rss/rss.rb b/lib/rss/rss.rb index 7ac1f42628..e53934f725 100644 --- a/lib/rss/rss.rb +++ b/lib/rss/rss.rb @@ -1,5 +1,35 @@ require "time" +class Time + class << Time + unless respond_to?(:w3cdtf) + def w3cdtf(date) + if /\A\s* + (-?\d+)-(\d\d)-(\d\d) + (?:T + (\d\d):(\d\d)(?::(\d\d))? + (\.\d+)? + (Z|[+-]\d\d:\d\d)?)? + \s*\z/ix =~ date and (($5 and $8) or (!$5 and !$8)) + datetime = [$1.to_i, $2.to_i, $3.to_i, $4.to_i, $5.to_i, $6.to_i] + datetime << $7.to_f * 1000000 if $7 + if $8 + Time.utc(*datetime) - zone_offset($8) + else + Time.local(*datetime) + end + else + raise ArgumentError.new("invalid date: #{date.inspect}") + end + end + end + end + + unless instance_methods.include?("w3cdtf") + alias w3cdtf iso8601 + end +end + require "English" require "rss/utils" require "rss/converter" @@ -168,10 +198,14 @@ EOC rescue ArgumentError raise NotAvailableValueError.new('#{disp_name}', new_value) end - elsif /\\A\\s*\\z/ !~ new_value.to_s - @#{name} = Time.parse(new_value) else @#{name} = nil + if /\\A\\s*\\z/ !~ new_value.to_s + begin + @#{name} = Time.parse(new_value) + rescue ArgumentError + end + end end end diff --git a/lib/rss/syndication.rb b/lib/rss/syndication.rb index 8f9ffb411f..8c10688b57 100644 --- a/lib/rss/syndication.rb +++ b/lib/rss/syndication.rb @@ -20,7 +20,7 @@ module RSS end %w(updateBase).each do |x| - install_date_element("\#{SY_PREFIX}_\#{x}", 'iso8601', x) + install_date_element("\#{SY_PREFIX}_\#{x}", 'w3cdtf', x) end alias_method(:_sy_updatePeriod=, :sy_updatePeriod=) |