# Re: parsedate doesn't work on Time.now.to\_s

**URL:** <https://www.ruby-forum.com/t/re-parsedate-doesnt-work-on-time-now-to-s/59527>\
**Category:** Ruby\
**Created:** [May 3, 2006, 9:32pm UTC](https://www.ruby-forum.com/t/re-parsedate-doesnt-work-on-time-now-to-s/59527 "2006-05-03T21:32:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![BergerS\_Daniel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bc8723/32.png) [@BergerS\_Daniel](https://www.ruby-forum.com/u/BergerS_Daniel)\
**Post date:** [May 3, 2006, 9:32pm UTC](https://www.ruby-forum.com/t/re-parsedate-doesnt-work-on-time-now-to-s/59527/1 "2006-05-03T21:32:59Z")

</div>

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

Take a look at time\_to\_s in time.c and you’ll see this line:

len = strftime(buf, 128, “%a %b %d %H:%M:%S %Z %Y”, &tobj-\>tm);

The ‘issue’ is %Z. Reading the man page on Solaris is merely says “time  
zone name or abbreviation”. How it determines which to use, I’m not  
sure. On Windows it’s apparently controlled by a registry setting  
somewhere (Windows also supports %z). So, my guess is most \*nix systems  
default to the abbreviation, while Windows defaults to the long name.

I don’t think we need to fix time\_to\_s, however. We need to fix  
ParseDate.

Regards,

Dan

This communication is the property of Qwest and may contain confidential  
or  
privileged information. Unauthorized use of this communication is  
strictly  
prohibited and may be unlawful. If you have received this communication  
in error, please immediately notify the sender by reply e-mail and  
destroy  
all copies of the communication and any attachments.

---

<div class="post-metadata">

**Author:** ![BergerS\_Daniel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bc8723/32.png) [@BergerS\_Daniel](https://www.ruby-forum.com/u/BergerS_Daniel)\
**Post date:** [May 3, 2006, 9:39pm UTC](https://www.ruby-forum.com/t/re-parsedate-doesnt-work-on-time-now-to-s/59527/2 "2006-05-03T21:39:17Z")

</div>

On 5/3/06, Berger, Daniel [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I don’t think we need to fix time\_to\_s, however. We need to fix  
> ParseDate.

> > Time.now.strftime(“%a %b %d %H:%M:%S %z %Y”)  
> > =\> “Wed May 03 15:37:18 Eastern Daylight Time 2006”

Note the use of “%z” as opposed to “%Z”. Windows is hosed.

-austin

---

<div class="post-metadata">

**Author:** ![BergerS\_Daniel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bc8723/32.png) [@BergerS\_Daniel](https://www.ruby-forum.com/u/BergerS_Daniel)\
**Post date:** [May 3, 2006, 11:09pm UTC](https://www.ruby-forum.com/t/re-parsedate-doesnt-work-on-time-now-to-s/59527/3 "2006-05-03T23:09:41Z")

</div>

On Thu, May 04, 2006 at 04:37:56AM +0900, Austin Z. wrote:

> > I don’t think we need to fix time\_to\_s, however. We need to fix  
> > ParseDate.
> 
> > > Time.now.strftime("%a %b %d %H:%M:%S %z %Y")  
> > > =\> “Wed May 03 15:37:18 Eastern Daylight Time 2006”
> 
> Note the use of “%z” as opposed to “%Z”. Windows is hosed.

The 1.8.4 source doesn’t document %z as an allowed conversion. The linux  
man page describes it as a GNU extension:

%z The time-zone as hour offset from GMT. Required to emit  
RFC822-conformant dates (using “%a, %d %b %Y %H:%M:%S %z”). (GNU)

So while I think Windows is hosed as a general principle, I think its  
within its rights in this case.

The ruby code isn’t validating the string input, just passing it to the  
strftime(), if ruby is supposed to support %z portably, it will have to  
do it itself. Its kindof useful to be able to use the local extensions,  
of course:

ruby -e ‘p Time.now.strftime("%P %r")’  
“pm 01:59:33 PM”

even if not very portable. Kind of a pain to have to reimplement library  
functions, but when they give access to non-standard behaviour, what is  
the right approach?

Cheers,  
Sam
