[RFC|Merged] Switch to PHP timezone handling

These requests for comments/change have lead to an implemented feature that has been successfully merged into the 3.1/Ascraeus branch. Everything listed in this forum will be available in phpBB 3.1.
Post Reply
Oleg
Posts: 1150
Joined: Tue Feb 23, 2010 2:38 am
Contact:

Re: [RFC|Accepted] Switch to PHP timezone handling

Post by Oleg »

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.

User avatar
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

Post by callumacrae »

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.
new Date().toString() provides more info:
"Wed Aug 24 2011 08:41:41 GMT+0100 (BST)"
It's standardised across all browsers and is easy to parse.
Made by developers, for developers!
My blog

teikjoon
Registered User
Posts: 3
Joined: Wed Aug 17, 2011 4:35 am

Re: [RFC|Accepted] Switch to PHP timezone handling

Post by teikjoon »

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) :

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> 
Which seems to work, working example here : http://www.workshop.twofishy.net/phpbb/ ... ezone.html

User avatar
Noxwizard
Support Team Leader
Support Team Leader
Posts: 137
Joined: Sun Dec 18, 2005 5:44 pm
Location: Texas
Contact:

Re: [RFC|Accepted] Switch to PHP timezone handling

Post by Noxwizard »

It does not correctly take DST into account. So UTC-5 EST was selected instead of UTC-6 CST w/DST.

teikjoon
Registered User
Posts: 3
Joined: Wed Aug 17, 2011 4:35 am

Re: [RFC|Accepted] Switch to PHP timezone handling

Post by teikjoon »

Hrmn, what about this...grep the timezone string for the word "Daylight", and if it appears, minus an hour from the offset :

Code: Select all

if (d.toString().indexOf("Daylight")!=-1) gmtHours--;
Have updated http://www.workshop.twofishy.net/phpbb/ ... ezone.html to reflect this change.
Noxwizard wrote:It does not correctly take DST into account. So UTC-5 EST was selected instead of UTC-6 CST w/DST.

User avatar
Noxwizard
Support Team Leader
Support Team Leader
Posts: 137
Joined: Sun Dec 18, 2005 5:44 pm
Location: Texas
Contact:

Re: [RFC|Accepted] Switch to PHP timezone handling

Post by Noxwizard »

The output varies by browser, so that won't really work. Additionally, I don't know if browsers localize those strings or not.

Chrome:

Code: Select all

Thu Aug 25 2011 02:06:02 GMT-0500 (Central Daylight Time)
IE:

Code: Select all

Thu Aug 25 02:06:02 CDT 2011

User avatar
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

Post by callumacrae »

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:

Code: Select all

Thu Aug 25 2011 02:06:02 GMT-0500 (Central Daylight Time)
IE:

Code: Select all

Thu Aug 25 02:06:02 CDT 2011
new Date().toString() is, according to DavidIQ, standardised across all browsers:
"Thu Aug 25 2011 19:54:00 GMT+0100 (BST)"
Made by developers, for developers!
My blog

User avatar
Noxwizard
Support Team Leader
Support Team Leader
Posts: 137
Joined: Sun Dec 18, 2005 5:44 pm
Location: Texas
Contact:

Re: [RFC|Accepted] Switch to PHP timezone handling

Post by Noxwizard »

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.

User avatar
DavidIQ
Customisations Team Leader
Customisations Team Leader
Posts: 1904
Joined: Thu Mar 02, 2006 4:29 pm
Location: Earth
Contact:

Re: [RFC|Accepted] Switch to PHP timezone handling

Post by DavidIQ »

callumacrae wrote:new Date().toString() is, according to DavidIQ, standardised across all browsers:
"Thu Aug 25 2011 19:54:00 GMT+0100 (BST)"
Yeah...they looked the same to me. Should have checked to begin with :roll: 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:
http://www.davidiq.net/jsdatetest.htm
Image

User avatar
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

Post by nickvergessen »

Safari 5.1

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
Opera 11.50

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-TeamNo Support via PM

Post Reply