In PHP5, the use of putenv can and is now commonly restricted so that it can
no longer be used.  Was considered a security issue.

A new function was created to deal with this called
date_default_timezone_set.

This function allows you to change on the fly what timezone is used for all
the date functions while not needing to know what locale the web server is
actually using..

For example:

date_default_timezone_set("US/Eastern");
echo "Eastern Time is currently: " . date('l jS \of F Y h:i:s A') . "<br
/>";
date_default_timezone_set("US/Central");
echo "Central Time is currently: " . date('l jS \of F Y h:i:s A') . "<br
/>";
date_default_timezone_set("US/Mountain");
echo "Mountain Time is currently: " . date('l jS \of F Y h:i:s A') . "<br
/>";
date_default_timezone_set("US/Arizona");
echo "Arizona Time is currently: " . date('l jS \of F Y h:i:s A') . "<br
/>";
date_default_timezone_set("US/Pacific");
echo "Pacific Time is currently: " . date('l jS \of F Y h:i:s A') . "<br
/>";

Which when I run it displays:

Eastern Time is currently: Friday 23rd of October 2009 11:41:10 AM
Central Time is currently: Friday 23rd of October 2009 10:41:10 AM
Mountain Time is currently: Friday 23rd of October 2009 09:41:10 AM
Arizona Time is currently: Friday 23rd of October 2009 08:41:10 AM
Pacific Time is currently: Friday 23rd of October 2009 08:41:10 AM

Note that Arizona does not use DST.... so it looks like it is in Pacific
when it is really always Mountain Standard.

You no longer need to know when DST starts (if it is used at all), what the
offset is from one timezone to another and you can use all of the new
Timezone values that are available:

http://www.php.net/manual/en/timezones.php

In addition if you look at the date function, There is a whole timezone
value section in the date() function that is affected by the timezone
setting.

So obtaining the number of offset sections so you can convert UTC is now
done for you like:

// Adjust for timezone
$utime1 += date("Z",$utime1);
$utime2 += date("Z",$utime2);

Used in the new version of my Google ICAL plugin to adjust the UTC
timestamps that Google Calendar uses so that I can properly display the real
times for the user using the timezone they are in.

This means that you could have a selector on a Calendar Agenda page where
the visitor can select what timezone they want the times to be output in.

It also effects complicated date functions like date_sunrise, date_sunset
etc...

In a multi-homed web server environment where one server is hosting sites
that may be for locations anywhere in the world, the function allows PHP to
output whatever locale they want it to be.

It is also suggested that you should never assume what timezone a web server
is using and specifically set it to the timezone you want to be using.

There are lots of enhancements in PHP5 which is why it is surprising that
anyone is still using PHP4.

Ref:

See example #1 - http://php.net/manual/en/function.date.php


On Fri, Oct 23, 2009 at 4:00 AM, The Editor <[email protected]> wrote:

>
> I'm not familiar with these functions, but wouldn't it be easier to do
>
>  putenv("TZ=" . BOLTconfig('timeZone'));
>
> Perhaps with some conversion or verification of values entered and/or
> a default setting of some sort?  I'm not sure how this would affect
> sites using timestamps. Does it affect their rendering or only the
> creation of new timestamps?
>
> Cheers,
> Dan
>
>
> On Thu, Oct 22, 2009 at 9:41 PM, Kevin <[email protected]> wrote:
> > I don't see anything in site.config for setting the timezone.
> >
> > Is there somewhere else that is set?
> >
> > Was expecting a setting in site.config like:
> >
> > timeZone: US/Eastern
> >
> > in site.config
> >
> > then in some initialization script somewhere...
> >
> > $timeZone = BOLTconfig('timeZone');
> > set_tz($$timeZone);
> >
> > ...
> >
> > The function set_tz works for both PHP 5.1+ and older
> >
> > function set_tz ($TZ){
> >     if (phpversion() >= "5.1.0") {
> >         date_default_timezone_set($TZ);
> >     } else {
> >         putenv("TZ=" . $TZ);
> >     }
> > }
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"BoltWire" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/boltwire?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to