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,

···

--
--
--<自由編碼人>--
Ing. Matias Pablo Brutti
Security Consultant
Email : matiasbrutti@gmail.com
Site: http://www.freedomcoder.com.ar

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

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

···

On Wed Jul 30 09:14:02 2008, Matias Pablo Brutti 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:

--
Fred O. Phillips

BBC7 7572 755F 83E0 3209 504A E4F7 874F 1545 9D41

Matias Pablo Brutti 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

···

--
       vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407

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.

···

On Tue, Jul 29, 2008 at 9:53 PM, Joel VanderWerf <vjoel@path.berkeley.edu>wrote:

Matias Pablo Brutti 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

--
     vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407

--
--
--<自由編碼人>--
Ing. Matias Pablo Brutti
Security Consultant
Email : matiasbrutti@gmail.com
Site: http://www.freedomcoder.com.ar

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&quot;\)
RSS::NotAvailableValueError: value <Tue, 29 Jul 2008 5:56 pm PDT> of tag
<lastBuildDate> 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:in
`__send__'
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:in
`call'
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:in
`parse'
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:in
`parse'
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 Brutti < matiasbrutti@gmail.com> wrote:

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.

On Tue, Jul 29, 2008 at 9:53 PM, Joel VanderWerf <vjoel@path.berkeley.edu > >wrote:

> Matias Pablo Brutti 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
>
> --
> vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407
>
>

--
--
--<自由編碼人>--
Ing. Matias Pablo Brutti
Security Consultant
Email : matiasbrutti@gmail.com
Site: http://www.freedomcoder.com.ar

--
--
--<自由編碼人>--
Ing. Matias Pablo Brutti
Security Consultant
Email : matiasbrutti@gmail.com
Site: http://www.freedomcoder.com.ar