[nycphp-talk] Localizing Time Zones

D C Krook dkrook at
Tue Aug 12 15:24:26 EDT 2003

We've been looking for a good way to customize a web-based work flow tool so 
that each user who logs in sees the time stamp of events in his own time 
zone, not that of the server.

For example, a developer in India who is given a task can see when it was 
assigned by the project manager in New York displayed in Bangalore time.  
Similarly the PM would see when the work was done relative to New York time. 
  Both users would see GMT as a frame of reference as well.

To implement this functionality, we've taken a look at Adam and David's PHP 
Cookbook where they address this very problem (Chapter 3, Calculating Time 
with Time Zones).

Their solution involves the temporary change of the TZ environment variable:

   "Calling putenv( ) before mktime( ) fools the system functions mktime( )
   uses into thinking they're in a different time zone. After the call to 
mktime( ),
   the correct time zone has to be restored."

   function pc_mktime($tz,$hr,$min,$sec,$mon,$day,$yr) {
       $a = mktime($hr,$min,$sec,$mon,$day,$yr);
       putenv('TZ=EST5EDT');   // change EST5EDT to your server's time zone!
       return $a;

This seems to be the solution we're after, but we're concerned about whether 
this is thread safe, particularly in the context of a heavy load server with 
lots of users redefining the TZ environment variable simultaneously.

The documentation of putenv() says the the environment variable will revert 
to its original value after the request, and we understand that explicitly 
resetting it as in the function above will offer a little better protection, 
but should we still worry that one user's putenv will clash with another's?  
If so, what is a better solution to time zone localization?

Thanks in advance,

Daniel Christer Krook || ||

The new MSN 8: smart spam protection and 2 months FREE*

More information about the talk mailing list