Parsedate doesn't work on Time.now.to_s


#1

require ‘parsedate’
Time.now
=> Tue May 02 20:17:57 GMT Standard Time 2006
ParseDate.parsedate(Time.now.to_s)
=> [nil, 5, 2, 20, 17, 57, “GMT”, 2]

It seems that parsedate is not able to detect the year from the standard
string conversion of a date/time. Is there another way to do this? Is it
the same in the US as for me here in the UK? It seems rather
inconsistent.

Julian


#2

Julian G. wrote:

require ‘parsedate’
Time.now
=> Tue May 02 20:17:57 GMT Standard Time 2006
ParseDate.parsedate(Time.now.to_s)
=> [nil, 5, 2, 20, 17, 57, “GMT”, 2]

It seems that parsedate is not able to detect the year from the standard
string conversion of a date/time. Is there another way to do this? Is it
the same in the US as for me here in the UK? It seems rather
inconsistent.

Hrmm. Works for me (ruby 1.8.4)

reirb(main):001:0> require ‘parsedate’
=> true
irb(main):002:0> Time.now
=> Tue May 02 15:46:56 EDT 2006
irb(main):003:0> ParseDate.parsedate( Time.now.to_s )
=> [2006, 5, 2, 15, 47, 7, “EDT”, 2]
irb(main):005:0> ENV[‘TZ’]=‘GMT’
=> “GMT”
irb(main):006:0> Time.now
=> Tue May 02 19:47:24 GMT 2006
irb(main):007:0> ParseDate.parsedate( Time.now.to_s )
=> [2006, 5, 2, 19, 47, 27, “GMT”, 2]

My guess is the “GMT Standard Time” is throwing it off.

irb(main):001:0> s = Time.now.to_s
=> “Tue May 02 15:48:28 EDT 2006”
irb(main):002:0> s.sub!( /EDT/, “GMT Standard Time” )
=> “Tue May 02 15:48:28 GMT Standard Time 2006”
irb(main):003:0> require ‘parsedate’
=> true
irb(main):004:0> ParseDate.parsedate( s )
=> [nil, 5, 2, 15, 48, 28, “GMT”, 2]


#3

Mike F. wrote:

My guess is the “GMT Standard Time” is throwing it off.

You are absolutely right. I have logged it as a bug.

Thanks,

Julian


#4

On Wed, May 03, 2006 at 06:40:17PM +0900, Julian G. wrote:

Mike F. wrote:

My guess is the “GMT Standard Time” is throwing it off.

You are absolutely right. I have logged it as a bug.

I think the bug is with Time.now, the format of its output is not
correct.

This is possibly a problem with the configuration of the system, of of
how it uses strftime(), since Time is a thin wrapper around time_t, and
strftime().

Sam