#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2007
    Posts
    50
    Rep Power
    10

    Noob-ish timezone question - set_default, or convert?


    Hi,
    I have a situation where users' timezones need to be taken into consideration.
    I have done it using some Ajax, the PHP side of which sets the default timezone to the user's timezone using
    Code:
    date_default_timezone_set($users_timezone_from_ajax)
    , in order to display a schedule retrieved from a list of times in a MySQL database.
    It works, and probably better than it needs to, as total accuracy is not critical.

    My question is:
    Should I be using date_default_timezone_set like this? Or should I be finding a way display a converted version of the timestamp, while leaving the default timezone in tact @ UTC?

    I think that mainly my problem is that I don't know if the default timezone is being changed ONLY for the current user...

    Thanks for any advice you can give.

    -unsub
    Last edited by unsub; November 26th, 2012 at 04:23 PM.
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,993
    Rep Power
    9397
    What you're doing makes the most sense to me. The script is basically running in the "context" of the user: getting stuff from here, doing stuff over there, and formatting times. The user is in some timezone and so whatever the script shows should be in that timezone too. In fact it's quite unlikely that it'll have to do anything for a different timezone.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2007
    Posts
    50
    Rep Power
    10
    OK, that's a word I should have been looking for "context"!

    So my assumption is (and this is probably going to sound really silly to at least a few people...) that setting the default timezone is not doing anything that's going to effect other users. By "default" it only means the default timezone in the 'context' of that instance of the script?

    The ability to set it in php.ini got me worrying... probably for no reason... I'm such a noob, jeez! :P

    Thanks so much for your reply
  6. #4
  7. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,993
    Rep Power
    9397
    Exactly. Each running PHP script is completely independent from all the other running PHP scripts, be they the same file or not. Separate memory, separate variables, separate everything. You have to go out of your way to make them share information.

    date_default_timezone_set() only sets the default timezone for the current script. Not like for the entire machine or for PHP as a whole.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2007
    Posts
    50
    Rep Power
    10
    Well that helps a lot, both in the 'context' of this question, and in general. Thanks again!

    Not sure if I need to mark this as [solved] or not... doesn't look to be the Devshed way, but I'll go and reread the forum guidelines.

    Best regards,
    -unsub
  10. #6
  11. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Sep 2002
    Location
    Seattle, U.S.A.
    Posts
    712
    Rep Power
    12
    Dealing with timezones is tricky stuff, check out this good thread on Stackoverflow for more information on timezone stuff:

    http://stackoverflow.com/questions/2...best-practices

IMN logo majestic logo threadwatch logo seochat tools logo