зеркало из https://github.com/github/ruby.git
* 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
This commit is contained in:
Родитель
7ead69e5b3
Коммит
cfbe158fae
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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=)
|
||||
|
|
Загрузка…
Ссылка в новой задаче