localtime is now wrong after server change

J

Jason

Until recently, my site was on a remote-hosted shared server; as of
today, I've completely upgraded to a dedicated.

I use to use the following to determine the timestamp for my forum:

($sec, $min, $hour, $day, $mon, $year, $wday) = (localtime(time +
(60*60)))[0,1,2,3,4,5,6];
$month = $mon + 1;
$year += 1900;

$today = "$year";
if ($month < 10) { $today .= "0"; }
$today .= "$month";
if ($day < 10) { $today .= "0"; }
$today .= "$day";

if ($hour < 10) { $hour = "0" . $hour; }
if ($min < 10) { $min = "0" . $min; }
if ($sec < 10) { $sec = "0" . $sec; }

$thistimestamp = $year . $month . $day . $hour . $min . $sec; # eg,
20060910040541


But after my server change, my hour is now an hour greater than it
should be (if it's 10am, this code states that it's 11am). I can't
figure out why, though, because through WHM, my server time matches my
local time.

What's the quickest way to decrease this code by an hour? Currently,
all posts in my forum are going to have to be corrected by hand (and I
get, on average, 1 post every 3 minutes), so I'm more concerned with
modifying the code quickly than anything else.

TIA,

Jason
 
A

anno4000

Jason said:
Until recently, my site was on a remote-hosted shared server; as of
today, I've completely upgraded to a dedicated.

What's a shared server and what's dedicated? This newsgroup is
about Perl, not remote hosting.
I use to use the following to determine the timestamp for my forum:

($sec, $min, $hour, $day, $mon, $year, $wday) = (localtime(time +
(60*60)))[0,1,2,3,4,5,6];
^^^^^^
This adds an hour to the time value. You have no idea why you are
doing this, do you?
$month = $mon + 1;
$year += 1900;

$today = "$year";
if ($month < 10) { $today .= "0"; }
$today .= "$month";
if ($day < 10) { $today .= "0"; }
$today .= "$day";

if ($hour < 10) { $hour = "0" . $hour; }
if ($min < 10) { $min = "0" . $min; }
if ($sec < 10) { $sec = "0" . $sec; }

$thistimestamp = $year . $month . $day . $hour . $min . $sec; # eg,
20060910040541


But after my server change, my hour is now an hour greater than it
should be (if it's 10am, this code states that it's 11am). I can't
figure out why, though, because through WHM, my server time matches my
local time.

What's WHM?

If you can't figure out the difference that means you either haven't
bothered to look at your own code or you don't understand it. You
are adding an hour yourself, for whatever reason.
What's the quickest way to decrease this code by an hour? Currently,
all posts in my forum are going to have to be corrected by hand (and I
get, on average, 1 post every 3 minutes), so I'm more concerned with
modifying the code quickly than anything else.

Get rid of the hour you are adding to the time value.

Your time manipulation routine looks like it's copied from Matt's
script archive, which means it looks like the work of a talented
sixteen-year-old who has just begun learning Perl.

Learn about POSIX::strftime and related functions. Without checking
every detail I'm sure you can generate your time format directly.

Anno
 
P

Peter J. Holzer

Until recently, my site was on a remote-hosted shared server; as of
today, I've completely upgraded to a dedicated.

I use to use the following to determine the timestamp for my forum:

($sec, $min, $hour, $day, $mon, $year, $wday) = (localtime(time +
(60*60)))[0,1,2,3,4,5,6]; [...]
But after my server change, my hour is now an hour greater than it
should be (if it's 10am, this code states that it's 11am). I can't
figure out why, though, because through WHM, my server time matches my
local time.

What's the quickest way to decrease this code by an hour?

How about removing the "+ (60*60)" in the code above? It looks like
previously someone couldn't be bothered to configure the timezone
correctly and just added 60 minutes to the time.
Currently, all posts in my forum are going to have to be corrected by
hand (and I get, on average, 1 post every 3 minutes), so I'm more
concerned with modifying the code quickly than anything else.

This is the attitude that got you in this mess. If something doesn't
work, find out why it doesn't work and fix the cause instead of fiddling
with the symptoms.

hp
 
M

Matt Garrish

A. Sinan Unur said:
Until recently, my site was on a remote-hosted shared server; as of
today, I've completely upgraded to a dedicated.

I use to use the following to determine the timestamp for my forum:

($sec, $min, $hour, $day, $mon, $year, $wday) = (localtime(time +
(60*60)))[0,1,2,3,4,5,6];
But after my server change, my hour is now an hour greater than it
should be (if it's 10am, this code states that it's 11am). I can't
figure out why,

Because you are adding one hour to the current time. How hard is that to
figure out?
though, because through WHM

WTF is WHM?

Wimpering hopeless moron? Oh wait, it wasn't in reference to himself. I
assume he means his web host management console, but one more reason I
hate when people use acronyms...

Matt
 
T

Tintin

Jason said:
Until recently, my site was on a remote-hosted shared server; as of
today, I've completely upgraded to a dedicated.

I use to use the following to determine the timestamp for my forum:

($sec, $min, $hour, $day, $mon, $year, $wday) = (localtime(time +
(60*60)))[0,1,2,3,4,5,6];
$month = $mon + 1;
$year += 1900;

$today = "$year";
if ($month < 10) { $today .= "0"; }
$today .= "$month";
if ($day < 10) { $today .= "0"; }
$today .= "$day";

if ($hour < 10) { $hour = "0" . $hour; }
if ($min < 10) { $min = "0" . $min; }
if ($sec < 10) { $sec = "0" . $sec; }

$thistimestamp = $year . $month . $day . $hour . $min . $sec; # eg,
20060910040541


But after my server change, my hour is now an hour greater than it
should be (if it's 10am, this code states that it's 11am). I can't
figure out why, though, because through WHM, my server time matches my
local time.

What's the quickest way to decrease this code by an hour? Currently,
all posts in my forum are going to have to be corrected by hand (and I
get, on average, 1 post every 3 minutes), so I'm more concerned with
modifying the code quickly than anything else.

Replace the entire awful code above with

use POSIX 'strftime';
my $thistimestamp = "%Y%m%d%H%M%S",localtime;

Much easier on the eye.
 
J

Jason

Regarding the first two replies... I appreciate the help, but when did
everyone on this NG get to be so rude? Wow.

Anyone remember how we used to all be helpful and sharing, proclaiming
that the internet (and Perl) was designed for the free exchange of
ideas and information? We would have never called someone a whimpering
moron just for not understanding the purpose of a line of code. I guess
this is what we have to look forward to with the next generation.
Here. you are adding one hour to the current time.

Thanks, and of course you're correct. I wrote that little bit of code
more than 8 years ago and have never needed to modify it, so it just
makes sense that I forgot why I did that. To answer the question of
"why didn't I change the time on the server," it's because (as I
mentioned in the original post) I was using a remote host, and didn't
have the ability to change their time zone.

All of this is crazy stupid.

#!/usr/bin/perl

use strict;
use warnings;

sub timestamp {
my ($sec, $min, $hour, $mday, $mon, $year) = (localtime)[0 .. 5];
sprintf(
'%4.4d%2.2d%2.2d%2.2d%2.2d%2.2d',
$year + 1900, $mon + 1, $mday, $hour, $min, $sec,
);
}

print timestamp(), "\n";

__END__

Or, just use POSIX::strftime as recommended.

Thank you for that. Now that I'm not in such a rush, I am spending time
going over my 8-year old program to make it a little faster and more
user friendly, and I'll definitely use your advice.

Because you are adding one hour to the current time. How hard is that to
figure out?

While working on old code, after having been awake for more than 48
hours... very hard! Be fair; if you weren't familiar with the logic,
what would make you think that 60*60 was equivalent to an hour?

WTF is WHM?

That's the name of the server management program that I use. It goes
along with cPanel; WHM is used by the owner to manage the websites, and
cPanel is given to the users to maintain their own part of the server
with limited abilities. I figured you all were aware of it; WHM is
really the most common software for hosting companies to use.

- J
 
T

Tad McClellan

Jason said:
but when did
everyone on this NG get to be so rude?


Last Thursday.

Anyone remember how we


You used to post here?

used to all be helpful and sharing,
We would have never called someone a whimpering
moron just for not understanding the purpose of a line of code.


For not understanding the purpose of a line of code *that you wrote yourself* ?

You must have had some purpose in mind when you wrote it...


If "we" would never have called someone out for cargo-culting code,
then things are _better_ now than then.

I guess
this is what we have to look forward to with the next generation.


Oh, are you an old guy or something?

While working on old code, after having been awake for more than 48
hours... very hard! Be fair;


Be a programmer.

(and is seems disrespectful of others to dump your problem on them
when in such a state.
)
if you weren't familiar with the logic,
what would make you think that 60*60 was equivalent to an hour?


There is no logic there, only straightforward arithmetic.

That's the name


With no vowels?

of the server management program that I use.
I figured you all were aware of it


Most uses of Perl are *not* in a CGI environment.

Perl is not CGI.
 
A

anno4000

Jason said:
Regarding the first two replies... I appreciate the help, but when did
everyone on this NG get to be so rude? Wow.

Anyone remember how we used to all be helpful and sharing, proclaiming
that the internet (and Perl) was designed for the free exchange of
ideas and information?

"We" used to be helpful?

You have never once given help to anyone on CLPM. Considering your
coding skills that is a good thing.

[...]
Thanks, and of course you're correct. I wrote that little bit of code
more than 8 years ago and have never needed to modify it, so it just
makes sense that I forgot why I did that.

You didn't write that code, you cribbed it from somewhere. This
crap is all over the net, almost literally. Don't try to pass off
(bad) folklore as your own work.
To answer the question of
"why didn't I change the time on the server," it's because (as I
mentioned in the original post) I was using a remote host, and didn't
have the ability to change their time zone.

Of course you can't change the server's time. It's a good thing
you can't because that would be the wrongest thing to do. You can
however change the time zone your program uses and that's what you
should have done. You don't need privileges for that.

[...]
While working on old code, after having been awake for more than 48
hours... very hard!

So you were too exhausted to keep a clear thought in your head, but
decided that was a good time to ask questions on Usenet? Thank you
very much for your consideration.
Be fair; if you weren't familiar with the logic,
what would make you think that 60*60 was equivalent to an hour?

Ah, but we all are familiar with the logic of "your" code. Is that
what you're saying?

You have entered the category of just another KLB.

Anno
 
D

Dave Weaver

Replace the entire awful code above with

use POSIX 'strftime';
my $thistimestamp = "%Y%m%d%H%M%S",localtime;

Much easier on the eye.

But, surprisingly, not so useful.

ITYM:

my $thistimestamp = strftime "%Y%m%d%H%M%S",localtime;
^^^^^^^^
 
A

A. Sinan Unur

@e63g2000cwd.googlegroups.com:

[ Relevant attributions an quotes were snipped by the OP. Reinserted. ]
Until recently, my site was on a remote-hosted shared server; as of
today, I've completely upgraded to a dedicated.

I use to use the following to determine the timestamp for my forum:

($sec, $min, $hour, $day, $mon, $year, $wday) = (localtime(time +
(60*60)))[0,1,2,3,4,5,6];

Here. you are adding one hour to the current time.
....

Be fair; if you weren't familiar with the logic,
what would make you think that 60*60 was equivalent to an hour?

Every Perl programmer ought to know or ought to be able to look up the
fact that time returns seconds since the epoch.

Every human being ought to know that there are 60 seconds in every
minute and 60 minutes in every hour. Therefore, 60*60 represents an hour
in seconds.

You are adding an hour to the current time.

It is natural to assume that someone posting in programming newsgroup is
familiar with logical reasoning. If not, programming is not for you.

Bye.

Sinan
 
T

Tintin

Dave Weaver said:
But, surprisingly, not so useful.

ITYM:

my $thistimestamp = strftime "%Y%m%d%H%M%S",localtime;
^^^^^^^^

Argh! I even tested the code, but unfortunately, I had the incorrect
version in my copy buffer.
 
J

Jason

"We" used to be helpful?
You have never once given help to anyone on CLPM. Considering your
coding skills that is a good thing.

Wow, I'm impressed with your ability to Google. I bow down to the
idiocy that is you.

Yes, I used to be a regular in this NG. I've been programming since
around '95, but I've gotten myself into a nice little rut where I
pretty much write the same type of thing, over and over. But back then,
I posted under a different name; nowadays, it's just too much trouble
to go through FreeAgent to make the occassional post, when I can use
Google more quickly.

Not that it's any of your business, but I currently own a web design
firm with more than 15 employees. My job is now day-to-day management
and the occassional debugging of programs, so while I used to be the
programmer, I really don't write programs to any large degree. Learn to
be nice; you'll probably be asking me for a job one day.

Not that you'll believe me. Not that I care.

You may think that you know everything, but as you become an adult,
you'll realize that there's more to life (and programming) than what
you think you know now. And a part of that is acting mature, and
treating people with respect.

You didn't write that code, you cribbed it from somewhere. This
crap is all over the net, almost literally. Don't try to pass off
(bad) folklore as your own work.

You're calling me a liar, I'm calling you a tiresome juvenile that's
quite simply wrong. Prove me wrong, and I'll shut up; until then, I
thank you for your assistance in the very minor Perl question, and will
say "you're welcome" to the "thank you" that is sure to come for my
lesson on respect.

Of course you can't change the server's time. It's a good thing
you can't because that would be the wrongest thing to do. You can
however change the time zone your program uses and that's what you
should have done. You don't need privileges for that.

"Wrongest?"

Obviously, I was referring to the time zone. See, even the wisest of us
can make a typing faux pas.

Ah, but we all are familiar with the logic of "your" code. Is that
what you're saying?

Yes, and apparently I was correct. Whether I was tired, and whether you
are a prick, I got the answer I needed, didn't I? You were just so
caught up in proving yourself to be correct that you couldn't help but
answer. I knew I could count on your kind.

And before you go thinking how important you are to the NG, you'll
notice that several other people replied in a much more adult manner,
saying the same thing.

Please don't bother wasting anymore bandwidth by this now off-topic
thread; it's not like I have time to read it. When I want your advice,
I'll be sure to post again.

To the rest of you, I apologize for falling into this childishness. I
certainly know better, but sometimes you just get dragged in. If this
guy isn't the norm around here (and I certainly hope he's not) then I
apologize for the ill thoughts I've had toward this once elite NG. If
he is the norm... then my, how the mighty have fallen.

- J
 
A

anno4000

Jason said:
"We" used to be helpful?

You have never once given help to anyone on CLPM. Considering your
coding skills that is a good thing.
[...]

Yes, I used to be a regular in this NG. ...
I posted under a different name;

It would be very easy to name that name. Until you do I don't believe
you.
Not that it's any of your business, but I currently own a web design
firm with more than 15 employees. My job is now day-to-day management
and the occassional debugging of programs, so while I used to be the
programmer, I really don't write programs to any large degree. Learn to
be nice; you'll probably be asking me for a job one day.

I won't.
You're calling me a liar, I'm calling you a tiresome juvenile that's
quite simply wrong. Prove me wrong,

I have. The code you used is widely available on the net, ultimately
originating in Matt's script archive. It's not your work.
"Wrongest?"

Quite possible in colloquial English. How is your German?
Obviously, I was referring to the time zone.

You were? Then why didn't you change it appropriately? The "+ 60*60"
kludge shows you have no idea how to use a time zone.
See, even the wisest of us can make a typing faux pas.

Another lie.
Yes, and apparently I was correct. Whether I was tired, and whether you
are a prick, I got the answer I needed, didn't I?

Every competent coder could find the error in about five minutes. All
you're proving is your incompetence.

Anno
 
A

anno4000

Jason said:
"We" used to be helpful?

You have never once given help to anyone on CLPM. Considering your
coding skills that is a good thing.
[...]

Yes, I used to be a regular in this NG. ...
I posted under a different name;

It would be very easy to name that name. Until you do I don't believe
you.

[snip]

Sorry, people. I should have recognized that clown earlier and ignored
him. My bozometer needs calibration.

Anno
 

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

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top