HTTP::Date

G

Gunnar Hjalmarsson

Tgone said:
I'm having problems with HTTP::Date displaying the wrong hour and
seconds.

Why do you think that time2str() is useful there?
print "$month/$day/$year @ $hour:$min\n";
-------------------------------------------------------------

This returns: 4/20/2006 @ 02:24

Any ideas?

Yes, you didn't read the docs for the module you are using carefully
enough before you posted here. Did you check the docs at all, or did you
just copy and paste some random code from somewhere?
 
S

Sherm Pendley

Tgone said:
I'm having problems with HTTP::Date displaying the wrong hour and
seconds.

-------------------------------------------------------------
$timestr = "2006-04-29 15:00:00";
my ($year, $month, $day, $hour, $min, $sec, $tz) =
parse_date(time2str($timestr));
print "$month/$day/$year @ $hour:$min\n";

On my system I get this:

1/01/1970 @ 00:33

The above code passes a string to time2str(), which as the HTTP::Date docs
state, "converts a machine time (seconds since epoch) to a string".

If I change your code to this:

$timestr = "2006-04-29 15:00:00";
my ($year, $month, $day, $hour, $min, $sec, $tz) =
parse_date(time2str(str2time($timestr)));
print "$month/$day/$year @ $hour:$min\n";

Then I get this:

4/29/2006 @ 19:00

The "19:00" is a result of str2time() defaulting to the local time zone,
whereas parse_date() expects GMT. If I pass an explicit time zone 'EDT'
to str2time(), I get the following:

4/20/2006 @ 03:30

Aha! The docs for str2time() state that, if a time zone other than "GMT"
or a numeric value is given, the module Time::Zone must be installed for
the string to be parsed correctly.

Now, if I specify GMT:

str2time($timestr, 'GMT')

I get this:

4/29/2006 @ 15:00

Note the hoops I had to jump through, just to duplicate your bug - what
you posted was obviously not your real code. So the above answer is just
a guess. If you want real answers, post real code.

sherm--
 
S

Sherm Pendley

Sherm Pendley said:
Aha! The docs for str2time() state that, if a time zone other than "GMT"
or a numeric value is given, the module Time::Zone must be installed for
the string to be parsed correctly.

Followup question: Shouldn't str2time() whine about an unknown time zone,
instead of silently returning bogus results?

sherm--
 
G

Gunnar Hjalmarsson

Sherm said:
If I change your code to this:

$timestr = "2006-04-29 15:00:00";
my ($year, $month, $day, $hour, $min, $sec, $tz) =
parse_date(time2str(str2time($timestr)));

Why not just parse_date($timestr) ?
 
S

Sherm Pendley

Gunnar Hjalmarsson said:
Why not just parse_date($timestr) ?

Because that produces the correct output, and my goal was to figure out
how the buggy output was being produced - the code he posted produces
completely different results.

sherm--
 
T

Tgone

it should be parse_date($timestr) not parse_date(time2str($timestr))

thanks for the help.
 
S

Sherm Pendley

Tgone said:
it should be parse_date($timestr) not parse_date(time2str($timestr))

No kidding, sherlock. I know what the *correct* code should be - my post
was trying to figure out what the *real* code was, since the code you
posted here did not produce the output you claimed.

sherm--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top