# Time.rb path

**URL:** <https://www.ruby-forum.com/t/time-rb-path/144483>\
**Category:** Ruby\
**Created:** [July 30, 2008, 2:19am UTC](https://www.ruby-forum.com/t/time-rb-path/144483 "2008-07-30T02:19:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matias\_Pablo\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ad7895/32.png) [@Matias\_Pablo\_B](https://www.ruby-forum.com/u/Matias_Pablo_B)\
**Post date:** [July 30, 2008, 2:19am UTC](https://www.ruby-forum.com/t/time-rb-path/144483/1 "2008-07-30T02:19:01Z")

</div>

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. 😃

Thanks a lot,

---

<div class="post-metadata">

**Author:** ![Matias\_Pablo\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ad7895/32.png) [@Matias\_Pablo\_B](https://www.ruby-forum.com/u/Matias_Pablo_B)\
**Post date:** [July 30, 2008, 2:28am UTC](https://www.ruby-forum.com/t/time-rb-path/144483/2 "2008-07-30T02:28:57Z")

</div>

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. 😃

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

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

---

<div class="post-metadata">

**Author:** ![Matias\_Pablo\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ad7895/32.png) [@Matias\_Pablo\_B](https://www.ruby-forum.com/u/Matias_Pablo_B)\
**Post date:** [July 30, 2008, 2:55am UTC](https://www.ruby-forum.com/t/time-rb-path/144483/3 "2008-07-30T02:55:16Z")

</div>

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. 😃

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

---

<div class="post-metadata">

**Author:** ![Matias\_Pablo\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ad7895/32.png) [@Matias\_Pablo\_B](https://www.ruby-forum.com/u/Matias_Pablo_B)\
**Post date:** [July 30, 2008, 3:13am UTC](https://www.ruby-forum.com/t/time-rb-path/144483/4 "2008-07-30T03:13:23Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Matias\_Pablo\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ad7895/32.png) [@Matias\_Pablo\_B](https://www.ruby-forum.com/u/Matias_Pablo_B)\
**Post date:** [July 30, 2008, 4:14am UTC](https://www.ruby-forum.com/t/time-rb-path/144483/5 "2008-07-30T04:14:13Z")

</div>

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](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: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 B. \<
