homepage Welcome to WebmasterWorld Guest from 54.145.183.190
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
Forum Library, Charter, Moderators: coopster & jatar k & phranque

Perl Server Side CGI Scripting Forum

    
6 Year old WebmasterWorld Perl Help for Timezones
lexipixel

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 4343920 posted 7:43 am on Jul 26, 2011 (gmt 0)

I needed to set the timezone for a group of calendar related scripts that run on a server in the mid-west (USA) because it's a Calendar of Events on a website near Boston, MA (USA).

WebmasterWorld to the rescue!

Since the site is on a shared server, it meant figuring how to set the timezone in the scripts (instead of just setting the time on the server).

I didn't want to play around with adding hours or seconds to 'localtime', (and risk needing to account for and test for dates, years or leapyear type situation that might occur), so I read the perldoc and a few examples that mentioned setting the 'TZ' ENVironment variable.

But all the examples I found were overly complicated, and none had the exact syntax for setting "Eastern Standard Time" and accounting for annual changes to "Eastern Daylight Savings Time".

So I did one more search for: perl $ENV{TZ}

...and what pops up? A WebmasterWorld thread from 2005 -- and of course it had simple, clear examples of the (4) US time zones and Greenwich Mean Time!


$ENV{'TZ'} = 'GMT0GMT';

$ENV{'TZ'} = 'EDT5EST';

$ENV{'TZ'} = 'CDT6CST';

$ENV{'TZ'} = 'MDT7MST';

$ENV{'TZ'} = 'PDT8PST';

[webmasterworld.com...]


I cut and pasted the line I needed into the scripts, and easy-peesy, it worked ba-geezy!

Thank you WebmasterWorld, now I know why I hang around here.

(This has been an unsolicited testimonial. I am not a paid endorser, out of work B-list actor, or retired boxer with tax problems. I have not received any compensation for posting this message.)

 

phranque

WebmasterWorld Administrator phranque us a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



 
Msg#: 4343920 posted 10:17 am on Jul 26, 2011 (gmt 0)

thanks, that was perfect lp! check is in the mail...
=8)

jk, but that is actually an interesting search result.
and bing must like freshness because this thread is already page 1 but no 6yo thread.
actually perl $ENV{TZ} returns no result in bing so i searched for perl ENV TZ.

and you can find all the time zone formats supported on your system if you can peruse /usr/share/zoneinfo/ and its subdirectories.
i.e., there also time zones such as America/Los_Angeles

lexipixel

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 4343920 posted 10:49 am on Jul 26, 2011 (gmt 0)

it looks like only Goog can deal with non-alphanumerics. Bing and Y! show nuthin.

I tried the search on a couple meta SE's, (DogPile and Mamma), they understand the query but only return the older Goog results.

I saw the $ENV{'TZ'} = "America/New_York"; values, but prefer the $ENV{'TZ'} = 'EDT5EST'; notation -- that way, in case NY ever secedes from the union, I don't have to change the scripts.

phranque

WebmasterWorld Administrator phranque us a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



 
Msg#: 4343920 posted 10:57 pm on Jul 26, 2011 (gmt 0)

fyi: regarding the *DTn*ST time zones, according to http://php.net/manual/en/timezones.others.php [php.net]:
Warning
Please do not use any of the timezones listed here (besides UTC), they only exist for backward compatible reasons.

i haven't found any perl, *nix, POSIX, ISO or ? references to explain why these should be avoided or a history of deprecation.
i'm guessing it is relevant to the status of the olson database.

also, i haven't seen any references that show the GMT0GMT tz designation.

lexipixel

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 4343920 posted 7:30 am on Jul 27, 2011 (gmt 0)

You had me going for a minute reading Php docs and forgetting I was patching perl scripts.

Adding the single line of code-

$ENV{'TZ'} = 'EDT5EST';

to the top of the scripts fixed a calendar that was rolling over at 2:00am instead of midnight... good enough for me for now.

If perl stops supporting those TZ values in the future, I'll fix again.


My old tag line:

"On time, done right, or cheap -- pick two!"

phranque

WebmasterWorld Administrator phranque us a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



 
Msg#: 4343920 posted 8:20 am on Jul 27, 2011 (gmt 0)

i'm sure your solution will get times right mid-summer/winter, but i would be concerned about getting the dates for the time change correctly, noting that the US law regarding observance of DST changed effective in 2007.
for example, i would be checking for proper behavior between the last sunday in october and the first sunday in november.
also note that while the state of arizona is in the mountain time zone, they don't observe DST.

lexipixel

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 4343920 posted 9:54 pm on Jul 27, 2011 (gmt 0)

I'm in Boston, MA.

It looks like I'll need to check on Sunday, November 6, 2011 to see if when Eastern Daylight Time (EDT) ends for 2011 it reverts to Eastern Standard Time (EST).

The calendar is for local events (for local users).. I make no adjustments for remote user times since the website and intended users are (or should be) in the same timezone. The only problem was the server isn't (in same timezone).

I'll check to see if the server is set to adjust for daylight savings time, (it would be on the same day, two hours earlier since it's in Utah).

FWIW -- I store all the event dates as strings in YYYYMMDD format, and they are never recalculated. I only check them against the current (perl / server) date to display the events for the day, (or upcoming events beyond the current date).

Programming dates and time are fun! (not)

phranque

WebmasterWorld Administrator phranque us a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



 
Msg#: 4343920 posted 10:10 pm on Jul 27, 2011 (gmt 0)

i would also check on the 1st of november to verify it didn't switch to EST a week early.

have you looked at the CPAN modules for DateTime calculations?

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved