phpBB

Development Discussion Board

phpBB's testing ground of bleeding edge code
Advanced search

[RFC] Local time handling by Javascript

Publish your own request for comments or patches for the next version of phpBB. Discuss the contributions and proposals of others. Upcoming releases are 3.1/Ascraeus and 3.2/Arsia.

[RFC] Local time handling by Javascript

Postby EXreaction » Sun Sep 12, 2010 1:33 am

Reasons:
Using PHP requires that users update their timezone setting at least once if they want the correct time displayed (assuming it would no longer be required for users to change DST twice a year with 3.1)
Using PHP means that guests are never shown local time

Since the sentiment is that we do not want to get rid of handling PHP side because of users who have javascript disabled, there is an easy way to support both. All that needs to be done is to modify user::format_date to output a slightly different timestamp string, something like:
Code: Select all
'<span class="localtime">' . (generated time) . '<span class="gmtime" style="display: none;">' . $gmepoch . '</span></span>'


Then, with a bit of jQuery, we grab the gmtime, format it to local time, then replace the generated time with the local time.

This would only require three edits in two files, the user class and the header, and would not cause any problems for styles or mods that are not updated (it would just show the time exactly as it does now).

I've setup a quick test of it here:
http://exreaction.lithiumstudios.org/phpBB3_time/

The only thing that would be left to do is to build a conversion table from the php format string to a javascript format string so that the date is displayed in the format the user selected.
My phpBB3 Mods: Advertisement Management | User Blog Mod | Anti-Spam ACP | Advanced Subscriptions | One Click Ban | From Author PM List | FAQ Manager | Forum Sponsors | Soft Delete | Auto Database Backup | Drag 'n Drop Forum List | HTML Ranks | Enable HTML
User avatar
EXreaction
Development Team
Development Team
 
Posts: 1259
Joined: Sat Sep 10, 2005 2:15 am

Re: [RFC] Local time handling by Javascript

Postby igorw » Sun Sep 12, 2010 9:08 am

Please use data- attributes for something like this:

Code: Select all
'<span class="localtime" data-timestamp="' . $gmepoch . '">' . (generated time) . '</span>'

jQuery:
Code: Select all
$('.localtime').each(function() {
    $(this).text(someMagic($(this).attr('data-timestamp')));
});
User avatar
igorw
Registered User
 
Posts: 500
Joined: Thu Jan 04, 2007 11:47 pm

Re: [RFC] Local time handling by Javascript

Postby EXreaction » Sun Sep 12, 2010 3:10 pm

I've never seen data- attributes used before. o.0
My phpBB3 Mods: Advertisement Management | User Blog Mod | Anti-Spam ACP | Advanced Subscriptions | One Click Ban | From Author PM List | FAQ Manager | Forum Sponsors | Soft Delete | Auto Database Backup | Drag 'n Drop Forum List | HTML Ranks | Enable HTML
User avatar
EXreaction
Development Team
Development Team
 
Posts: 1259
Joined: Sat Sep 10, 2005 2:15 am

Re: [RFC] Local time handling by Javascript

Postby Erik Frèrejean » Sun Sep 12, 2010 3:21 pm

I might be mistaken but aren't the data attributes introduced in the HTML 5 spec?
Available on .com
Support Toolkit developer
User avatar
Erik Frèrejean
Registered User
 
Posts: 207
Joined: Thu Oct 25, 2007 2:25 pm
Location: surfnet

Re: [RFC] Local time handling by Javascript

Postby igorw » Sun Sep 12, 2010 6:32 pm

Erik Frèrejean wrote:I might be mistaken but aren't the data attributes introduced in the HTML 5 spec?

Yes, that is correct. But this is phpBB 3.2 so it might be feasible, plus it's already supported by all browsers (afaik). I guess we'll have to see if we want to go down that route.
User avatar
igorw
Registered User
 
Posts: 500
Joined: Thu Jan 04, 2007 11:47 pm

Re: [RFC] Local time handling by Javascript

Postby Erik Frèrejean » Sun Sep 12, 2010 7:30 pm

I missed that this was in the 3.2 forum, I would swear that it was in 3.1 :|. Yes for 3.2 this probably is feasible.
Available on .com
Support Toolkit developer
User avatar
Erik Frèrejean
Registered User
 
Posts: 207
Joined: Thu Oct 25, 2007 2:25 pm
Location: surfnet

Re: [RFC] Local time handling by Javascript

Postby ToonArmy » Tue Sep 14, 2010 10:18 am

eviL3 wrote:
Erik Frèrejean wrote:I might be mistaken but aren't the data attributes introduced in the HTML 5 spec?

Yes, that is correct. But this is phpBB 3.2 so it might be feasible, plus it's already supported by all browsers (afaik). I guess we'll have to see if we want to go down that route.

http://dev.w3.org/html5/html-author/#the-time-element
Chris SmithBlogXMOOhlohArea51WikiNo support via PM/IM
Image
User avatar
ToonArmy
Registered User
 
Posts: 335
Joined: Fri Mar 26, 2004 7:31 pm
Location: Bristol, UK

Re: [RFC] Local time handling by Javascript

Postby Truemedia » Tue Sep 14, 2010 12:58 pm

Why dont you figure the timezone out by comparing the js time with php time in the same range then use the php time of the matching timezone. This way you don't need to store the javascript time for each user in the database and if the user wants to change the time they can correct the timezone from ucp.

This would be less resource intensive and means the phpbb tables dont need to be modified. Also possably adding automatic timezone by default on the registration page with an optional timezone selector, Therefore dealing with people using correct and wrong times on there computer.
Truemedia
Registered User
 
Posts: 5
Joined: Sun Aug 29, 2010 1:06 pm

Re: [RFC] Local time handling by Javascript

Postby xerces8 » Sun Nov 28, 2010 5:22 pm

I'm just a forum user, but want to voice my support for this.

With date/time output using JavaScript toLocaleString (or similar) both time format and timezone/DST will be correct for majority of users, without any manual settings from their side, or even the requirement of registration or login.
(users with no JS enabled will get what they have now, so there is no loss)
The only problem might be systems with wrong TZ settings, but if the user can not set his OS TZ, then he probably can't set it in a forum profile either.
xerces8
Registered User
 
Posts: 11
Joined: Sat Nov 27, 2010 1:12 pm

Re: [RFC] Local time handling by Javascript

Postby xerces8 » Thu Dec 16, 2010 11:28 pm

xerces8 wrote:With date/time output using JavaScript toLocaleString (or similar) both time format and timezone/DST will be correct for majority of users, without any manual settings from their side, or even the requirement of registration or login.

Here I put a demo: http://xerces8.comli.com/timepage.html
xerces8
Registered User
 
Posts: 11
Joined: Sat Nov 27, 2010 1:12 pm

Next

Return to [3.x] RFCs

Who is online

Users browsing this forum: No registered users and 10 guests