PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 26th, 2012, 03:20 PM
unsub unsub is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2007
Posts: 50 unsub User rank is Corporal (100 - 500 Reputation Level)unsub User rank is Corporal (100 - 500 Reputation Level)unsub User rank is Corporal (100 - 500 Reputation Level)unsub User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 12 h 29 m 49 sec
Reputation Power: 9
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.

Reply With Quote
  #2  
Old November 26th, 2012, 05:18 PM
requinix's Avatar
requinix requinix is offline
Still alive
Click here for more information.
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,690 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 4 Days 3 h 43 m 47 sec
Reputation Power: 8969
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
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.

Reply With Quote
  #3  
Old November 26th, 2012, 07:54 PM
unsub unsub is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2007
Posts: 50 unsub User rank is Corporal (100 - 500 Reputation Level)unsub User rank is Corporal (100 - 500 Reputation Level)unsub User rank is Corporal (100 - 500 Reputation Level)unsub User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 12 h 29 m 49 sec
Reputation Power: 9
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

Reply With Quote
  #4  
Old November 26th, 2012, 08:46 PM
requinix's Avatar
requinix requinix is offline
Still alive
Click here for more information.
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,690 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 4 Days 3 h 43 m 47 sec
Reputation Power: 8969
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
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.

Reply With Quote
  #5  
Old November 26th, 2012, 10:43 PM
unsub unsub is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2007
Posts: 50 unsub User rank is Corporal (100 - 500 Reputation Level)unsub User rank is Corporal (100 - 500 Reputation Level)unsub User rank is Corporal (100 - 500 Reputation Level)unsub User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 12 h 29 m 49 sec
Reputation Power: 9
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

Reply With Quote
  #6  
Old November 26th, 2012, 11:54 PM
msteudel's Avatar
msteudel msteudel is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Sep 2002
Location: Seattle, U.S.A.
Posts: 712 msteudel User rank is Lance Corporal (50 - 100 Reputation Level)msteudel User rank is Lance Corporal (50 - 100 Reputation Level)msteudel User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 4 Days 11 h 4 m 59 sec
Reputation Power: 11
Dealing with timezones is tricky stuff, check out this good thread on Stackoverflow for more information on timezone stuff:

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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Noob-ish timezone question - set_default, or convert?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap