Forum: Ruby parsedate doesn't work on Time.now.to_s

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
7284167ee91af66fcd739a42e3df3804?d=identicon&s=25 Julian Gall (juliangall)
on 2006-05-02 21:21
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
357558a6682f4d6624594763d9acdb35?d=identicon&s=25 Mike Fletcher (fletch)
on 2006-05-02 21:49
Julian Gall 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]
7284167ee91af66fcd739a42e3df3804?d=identicon&s=25 Julian Gall (juliangall)
on 2006-05-03 11:40
Mike Fletcher 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
0ca6e5c33d7e7ff901d75ff0b13d9e1c?d=identicon&s=25 Sam Roberts (Guest)
on 2006-05-03 20:34
(Received via mailing list)
On Wed, May 03, 2006 at 06:40:17PM +0900, Julian Gall wrote:
> Mike Fletcher 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
This topic is locked and can not be replied to.