News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

PHP time( )

Started by Sir Osis of Liver, December 07, 2023, 04:48:49 PM

Previous topic - Next topic

Sir Osis of Liver

Tinkering with a script that displays current day of month.  Server is in EST, but I use EDT all year round, and my desktop is set to EDT.  At 2300 my time script jumps to next day, an hour early for me.  PHP time() = $_SERVER['REQUEST_TIME'] = EST, so I'm trying to add an hour to server time at top of script -


$_SERVER['REQUEST_TIME'] = $_SERVER['REQUEST_TIME'] +3600;
echo $_SERVER['REQUEST_TIME'];


It displays the correct EDT time.  Question is, will the script use time() (EST), actual $_SERVER['REQUEST_TIME'] (EST), or $_SERVER['REQUEST_TIME'] + 3600 (EDT).  Or is there a correct way to do it?

When in Emor, do as the Snamors.
                              - D. Lister

Sesquipedalian

Rather than messing around with timestamps, just use DateTime and DateTimeZone. You will save yourself from lots of pain.
I promise you nothing.

Sesqu... Sesqui... what?
Sesquipedalian, the best word in the English language.

Sir Osis of Liver

Will look at that tonight (if brain fog hasn't rolled in by then :( ).

Thanks.
When in Emor, do as the Snamors.
                              - D. Lister

Sir Osis of Liver

Not sure why, but this works -

//Correct for EDT
date_default_timezone_set('America/Halifax');

      Even a blind pig occasionally finds a mushroom.

When in Emor, do as the Snamors.
                              - D. Lister

Sesquipedalian

It won't always. Halifax uses Atlantic Time, which is one hour ahead of Eastern Time. But it also switches between Standard and Daylight Saving Time, just like Eastern Time does. So it does what you want right now, but it won't in a few months.
I promise you nothing.

Sesqu... Sesqui... what?
Sesquipedalian, the best word in the English language.

Sir Osis of Liver

I expect to have to switch the script back to EDT when time changes in spring, that's just a matter of commenting out that line.  I'm accustomed to making some adjustments to stay in EDT year round.

When in Emor, do as the Snamors.
                              - D. Lister

Sesquipedalian

I'm not sure why you would want to do that in the first place—it sounds like a situation where you are trying to intentionally induce bad behaviour one script in order to maintain compatibility with another script that has bad behaviour.

But since you apparently do want to do that for <reasons>, then I suggest that you choose the appropriate Etc/GMT-n time zone for your purposes.
I promise you nothing.

Sesqu... Sesqui... what?
Sesquipedalian, the best word in the English language.

Sir Osis of Liver

This is a standalone script for my use only, it'll be linked from forum main menu by a button only I can see. Doesn't affect anything in forum code.  The server is in Canada in EST, so advancing the time zone one hour to Atlantic time causes the script to run in EDT.  It's been many years since I bothered changing my clocks from EST to EDT and back.  I don't need the government to tell me what time it is.
When in Emor, do as the Snamors.
                              - D. Lister

live627

Quote from: Sir Osis of Liver on December 10, 2023, 01:04:22 PM.  I don't need the government to tell me what time it is.
Me neither. That's why I live in Arizona.

Sesquipedalian

#9
If that's your stance, why not set your clock to Local Mean Time for your exact longitude? If you're not going to follow the time conventions of your neighbours, there's no point being half-assed about it. Throw off those authoritarian shackles and set your clock by observing when the sun is at its zenith over your house! Down with The Man's oppressive insistence on coordinated timekeeping, however useful it might be for for easing social interactions, travel plans, telecommunications, and whatnot in this newfangled era where information can travel faster than a horse! We don't need conventions! We just need MOAR FREDOM!!!

Also, if your server is in Canada and uses Eastern Time, then unless it is located in the small town of Atikokan, Ontario, it is in fact located in a place that switches between Standard Time and Daylight Saving Time.
I promise you nothing.

Sesqu... Sesqui... what?
Sesquipedalian, the best word in the English language.

shawnb61

The only real problem I see is getting kicked out of bars an hour early half the year.
A question worth asking is born in experience & driven by necessity. - Fripp

Tyrsson

Quote from: shawnb61 on December 10, 2023, 03:21:56 PMThe only real problem I see is getting kicked out of bars an hour early half the year.
Or, the whiskey store  O:)
PM at your own risk, some I answer, if they are interesting, some I ignore.

Advertisement: