# Parsedate doesn't work on Time.now.to\_s

**URL:** <https://www.ruby-forum.com/t/parsedate-doesnt-work-on-time-now-to-s/59260>\
**Category:** Ruby\
**Created:** [May 2, 2006, 9:21pm UTC](https://www.ruby-forum.com/t/parsedate-doesnt-work-on-time-now-to-s/59260 "2006-05-02T21:21:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![juliangall](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9e8a1a/32.png) [@juliangall](https://www.ruby-forum.com/u/juliangall)\
**Post date:** [May 2, 2006, 9:21pm UTC](https://www.ruby-forum.com/t/parsedate-doesnt-work-on-time-now-to-s/59260/1 "2006-05-02T21:21:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![juliangall](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9e8a1a/32.png) [@juliangall](https://www.ruby-forum.com/u/juliangall)\
**Post date:** [May 2, 2006, 9:49pm UTC](https://www.ruby-forum.com/t/parsedate-doesnt-work-on-time-now-to-s/59260/2 "2006-05-02T21:49:55Z")

</div>

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]

---

<div class="post-metadata">

**Author:** ![juliangall](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9e8a1a/32.png) [@juliangall](https://www.ruby-forum.com/u/juliangall)\
**Post date:** [May 3, 2006, 11:40am UTC](https://www.ruby-forum.com/t/parsedate-doesnt-work-on-time-now-to-s/59260/3 "2006-05-03T11:40:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![juliangall](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9e8a1a/32.png) [@juliangall](https://www.ruby-forum.com/u/juliangall)\
**Post date:** [May 3, 2006, 8:34pm UTC](https://www.ruby-forum.com/t/parsedate-doesnt-work-on-time-now-to-s/59260/4 "2006-05-03T20:34:15Z")

</div>

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
