Time.rb path

While working on a project I came across with a problem that I traced to
Time.rb. Some rss feeds return time in the following format “Mon, 28 Jul
2008 5:56 pm PDT”. Searching inside time.rb code I was not able to find
any
rfc capable of parsing that string. Is there any rfc which manages
this
type of time format which contains AM/PM ? (rfc2822 does not) if there
is
and it is not yet implemented I would more than glad to code it, it is
just
that I do not know I should just monkey patch the class to make this
work or
if I could implement an existent rfc that will solve the issue, and
truly I
would rather do the last, “mucho” more interesting. :smiley:

Thanks a lot,

On Wed Jul 30 09:14:02 2008, Matias Pablo B. wrote:

While working on a project I came across with a problem that I traced to
Time.rb. Some rss feeds return time in the following format “Mon, 28 Jul
2008 5:56 pm PDT”. Searching inside time.rb code I was not able to find any
rfc capable of parsing that string. Is there any rfc which manages this
type of time format which contains AM/PM ? (rfc2822 does not) if there is
and it is not yet implemented I would more than glad to code it, it is just
that I do not know I should just monkey patch the class to make this work or
if I could implement an existent rfc that will solve the issue, and truly I
would rather do the last, “mucho” more interesting. :smiley:

You might want to have a look at chronic[1] it might help.

[1] http://chronic.rubyforge.org/

Matias Pablo B. wrote:

While working on a project I came across with a problem that I traced to
Time.rb. Some rss feeds return time in the following format “Mon, 28 Jul
2008 5:56 pm PDT”. Searching inside time.rb code I was not able to find any
rfc capable of parsing that string. Is there any rfc which manages this
type of time format which contains AM/PM ? (rfc2822 does not) if there is
and it is not yet implemented I would more than glad to code it, it is just
that I do not know I should just monkey patch the class to make this work or
if I could implement an existent rfc that will solve the issue, and truly I
would rather do the last, “mucho” more interesting. :smiley:

Doesn’t this work?

$ ruby -r time -e ‘puts Time.parse “Mon, 28 Jul 2008 5:56 pm PDT”’
Mon Jul 28 17:56:00 -0700 2008

yes it does, the problems is that the rss lib to validate the
lastbuildDate
tag or the pubDate tag use Time.send(type, value) to validate, which
fails and makes rss not to finish parsing, I can pass a false parameter
not
to check the date and it works but I want to validate it, hence my
issue.

I think the problem is on line 280 of rss.rb (shown below) because it
raises
and crashes the feed. Which, I think is going a little to far. I think
it
could just do a @#{name} = Time.parse(new_value) to default to some
value
instead of raising and return the whole parsing nil just because of
that.
Well it is just an opinion. I might be missing something and be
completely
wrong.

Cheers

CODE of rss.rb:

[…]
270 def date_writer(name, type, disp_name=name)
271 module_eval(<<-EOC, get_file_and_line_from_caller(2))
272 def #{name}=(new_value)
273 if new_value.nil? or new_value.kind_of?(Time)
274 @#{name} = new_value
275 else
276 if @do_validate
277 begin
278 @#{name} = Time.send(’#{type}’, new_value)
279 rescue ArgumentError
280 raise NotAvailableValueError.new(’#{disp_name}’,
new_value) << HERE
281 end
282 else
283 @#{name} = nil
284 if /\A\s
\z/ !~ new_value.to_s
285 begin
286 @#{name} = Time.parse(new_value)
287 rescue ArgumentError
288 end
289 end
290 end
291 end
292
293 # Is it need?
294 if @#{name}
295 class << @#{name}
296 undef_method(:to_s)
297 alias_method(:to_s, :#{type})
298 end
299 end
300
301 end
302 EOC
303 end
[…]

Just in case this is a code sample of what I’m doing:

require ‘rss’
require ‘open-uri’

feed=RSS::Parser.parse("
http://weather.yahooapis.com/forecastrss?p=USCA1116")
RSS::NotAvailableValueError: value <Tue, 29 Jul 2008 5:56 pm PDT> of tag
is not available.
from
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rss/0.9.rb:100:in
lastBuildDate=' from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rss/parser.rb:393:insend
from
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rss/parser.rb:393:in
start_get_text_element' from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rss/parser.rb:329:incall’
from
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rss/parser.rb:329:in
tag_end' from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rexml/parsers/streamparser.rb:26:inparse’
from
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rexml/document.rb:200:in
parse_stream' from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rss/rexmlparser.rb:22:in_parse’
from
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rss/parser.rb:163:in
parse' from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rss/parser.rb:78:inparse’
from (irb):3
from
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rational.rb:476

On Tue, Jul 29, 2008 at 10:11 PM, Matias Pablo B. <

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs