Re: parsedate doesn't work on Time.now.to_s

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.

On 5/3/06, Berger, Daniel [email protected] 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

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