[RFC|Merged] Switch to PHP timezone handling
Re: [RFC|Accepted] Switch to PHP timezone handling
It is impossible to know what timezone a user is in from their dst offset alone.
It should also be possible to choose any timezone we support whenever timezone choice is presented.
It should also be possible to choose any timezone we support whenever timezone choice is presented.
- callumacrae
- Former Team Member
- Posts: 1046
- Joined: Tue Apr 27, 2010 9:37 am
- Location: England
- Contact:
Re: [RFC|Accepted] Switch to PHP timezone handling
new Date().toString() provides more info:Oleg wrote:It is impossible to know what timezone a user is in from their dst offset alone.
It should also be possible to choose any timezone we support whenever timezone choice is presented.
It's standardised across all browsers and is easy to parse."Wed Aug 24 2011 08:41:41 GMT+0100 (BST)"
Re: [RFC|Accepted] Switch to PHP timezone handling
I've wrote a small bit of Javascript which calculates your timezone offset, and then uses this to select the "default" option (which is hardcoded to UTC +0) :
Which seems to work, working example here : http://www.workshop.twofishy.net/phpbb/ ... ezone.html
Code: Select all
<script type="text/javascript">
var d = new Date()
var gmtHours = -d.getTimezoneOffset()/60;
for (var i=0;i<document.getElementById("timezone").options.length;i++) {
if (document.getElementById("timezone").options[i].value == gmtHours)
document.getElementById("timezone").options[i].selected = true;
}
</script>
- Noxwizard Online
- Support Team Leader
- Posts: 138
- Joined: Sun Dec 18, 2005 5:44 pm
- Location: Texas
- Contact:
Re: [RFC|Accepted] Switch to PHP timezone handling
It does not correctly take DST into account. So UTC-5 EST was selected instead of UTC-6 CST w/DST.
Re: [RFC|Accepted] Switch to PHP timezone handling
Hrmn, what about this...grep the timezone string for the word "Daylight", and if it appears, minus an hour from the offset :
Have updated http://www.workshop.twofishy.net/phpbb/ ... ezone.html to reflect this change.
Code: Select all
if (d.toString().indexOf("Daylight")!=-1) gmtHours--;
Noxwizard wrote:It does not correctly take DST into account. So UTC-5 EST was selected instead of UTC-6 CST w/DST.
- Noxwizard Online
- Support Team Leader
- Posts: 138
- Joined: Sun Dec 18, 2005 5:44 pm
- Location: Texas
- Contact:
Re: [RFC|Accepted] Switch to PHP timezone handling
The output varies by browser, so that won't really work. Additionally, I don't know if browsers localize those strings or not.
Chrome:
IE:
Chrome:
Code: Select all
Thu Aug 25 2011 02:06:02 GMT-0500 (Central Daylight Time)
Code: Select all
Thu Aug 25 02:06:02 CDT 2011
- callumacrae
- Former Team Member
- Posts: 1046
- Joined: Tue Apr 27, 2010 9:37 am
- Location: England
- Contact:
Re: [RFC|Accepted] Switch to PHP timezone handling
new Date().toString() is, according to DavidIQ, standardised across all browsers:Noxwizard wrote:The output varies by browser, so that won't really work. Additionally, I don't know if browsers localize those strings or not.
Chrome:IE:Code: Select all
Thu Aug 25 2011 02:06:02 GMT-0500 (Central Daylight Time)
Code: Select all
Thu Aug 25 02:06:02 CDT 2011
"Thu Aug 25 2011 19:54:00 GMT+0100 (BST)"
- Noxwizard Online
- Support Team Leader
- Posts: 138
- Joined: Sun Dec 18, 2005 5:44 pm
- Location: Texas
- Contact:
Re: [RFC|Accepted] Switch to PHP timezone handling
I'm not sure in what version of the browsers they plan to do that in, but the two I gave are using the JavaScript you listed. That's Chrome 13 and IE 9.
- DavidIQ
- Customisations Team Leader
- Posts: 1904
- Joined: Thu Mar 02, 2006 4:29 pm
- Location: Earth
- Contact:
Re: [RFC|Accepted] Switch to PHP timezone handling
Yeah...they looked the same to me. Should have checked to begin with Might be best to go with getTimezoneOffset and try to figure it out from there as that seems pretty standard between at least FF and IE9:callumacrae wrote:new Date().toString() is, according to DavidIQ, standardised across all browsers:"Thu Aug 25 2011 19:54:00 GMT+0100 (BST)"
http://www.davidiq.net/jsdatetest.htm
- nickvergessen
- Former Team Member
- Posts: 733
- Joined: Sun Oct 07, 2007 11:54 am
- Location: Stuttgart, Germany
- Contact:
Re: [RFC|Accepted] Switch to PHP timezone handling
Safari 5.1
Opera 11.50
Code: Select all
.toString() = Fri Aug 26 2011 00:09:29 GMT+0200 (Mitteleuropäische Sommerzeit)
.toUTCString() = Thu, 25 Aug 2011 22:09:29 GMT
.getTimezoneOffset() = -120
Code: Select all
.toString() = Fri Aug 26 2011 00:09:34 GMT+0200
.toUTCString() = Thu, 25 Aug 2011 22:09:34 GMT
.getTimezoneOffset() = -120
Member of the Development-Team — No Support via PM