[FIX] Daylight Saving Time

A place for MOD Authors to post and receive feedback on MODs still in development. No MODs within this forum should be used within a live environment! No new topics are allowed in this forum.
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

IMPORTANT: MOD Development Forum rules

On February 1, 2009 this forum will be set to read only as part of retiring of phpBB2.
sublime1
Registered User
Posts: 100
Joined: Sun Aug 03, 2003 10:14 pm

Post by sublime1 »

Great mod. Seems to work like a charm. Thanks!
thetechpub
Registered User
Posts: 18
Joined: Fri May 02, 2003 3:33 pm

Post by thetechpub »

Failed to work when I did it to the current version of phpBB2... Got an error code page because of it. Replaced the file with the original again, and it works fine.
wysiwygs
Registered User
Posts: 22
Joined: Tue Aug 05, 2003 6:41 am

Post by wysiwygs »

Guess that means that you got it working. The area of change in "includes\functions.php" has not changed from 2.4 to 2.6. So the fix should apply without problems. But you never know about uploads... sometimes the FTP process reports that it was successful, when it really wasn't for one reason or another.

Wysiwygs
thetechpub
Registered User
Posts: 18
Joined: Fri May 02, 2003 3:33 pm

Post by thetechpub »

Actually, the original file makes the boards work, the altered one doesn't. I did a copy/paste of the contents from the original post here into a dupe of the file (to keep the original safe). Uploaded the altered, phpBB (2.0.8) gave an error message screen. Replaced the file with the unaltered one and the boards worked again (no adjustment for daylight savings, but at least the boards work).
wysiwygs
Registered User
Posts: 22
Joined: Tue Aug 05, 2003 6:41 am

Post by wysiwygs »

Ok... since I don't know your experience level... do you understand "find" and "replace"? In other words, one line of code is being replaced by two lines of code and comments.

This line:

Code: Select all

	return ( !empty($translate) ) ? strtr(@gmdate($format, $gmepoch + (3600 * $tz)), $translate) : @gmdate($format, $gmepoch + (3600 * $tz));
is being replaced with:

Code: Select all

// Begin Daylight Saving Time MOD
//	return ( !empty($translate) ) ? strtr(@gmdate($format, $gmepoch + (3600 * $tz)), $translate) : @gmdate($format, $gmepoch + (3600 * $tz));

    $dst = date('I', $gmepoch) * 3600;

	return ( !empty($translate) ) ? strtr(@gmdate($format, $gmepoch + (3600 * $tz) + $dst), $translate) : @gmdate($format, $gmepoch + (3600 * $tz) + $dst);
// End Daylight Saving Time MOD
Unless you retyped as opposed to "copy and paste" the change, I am not certain why you would have a problem. The complete "create_date" function, with change, is as follows:

Code: Select all

//
// Create date/time from format and timezone
//
function create_date($format, $gmepoch, $tz)
{
	global $board_config, $lang;
	static $translate;

	if ( empty($translate) && $board_config['default_lang'] != 'english' )
	{
		@reset($lang['datetime']);
		while ( list($match, $replace) = @each($lang['datetime']) )
		{
			$translate[$match] = $replace;
		}
	}

// Begin Daylight Saving Time MOD
//	return ( !empty($translate) ) ? strtr(@gmdate($format, $gmepoch + (3600 * $tz)), $translate) : @gmdate($format, $gmepoch + (3600 * $tz));

    $dst = date('I', $gmepoch) * 3600;

	return ( !empty($translate) ) ? strtr(@gmdate($format, $gmepoch + (3600 * $tz) + $dst), $translate) : @gmdate($format, $gmepoch + (3600 * $tz) + $dst);
// End Daylight Saving Time MOD
}
The trick is the use of the $dst variable to determine if the server is "in" Daylight Saving Time. It does this through the I (capital eye) option of the date() function. If the server is "in" Daylight Saving Time, $dst = 1 * 3600 (1 hour in seconds). If the server is NOT "in" Daylight Saving Time, $dst = 0 * 3600 (or 0, as 0 times anything is 0).

Hope this helps.

Wysiwygs
jayb
Registered User
Posts: 9
Joined: Mon Jan 19, 2004 2:10 am

Post by jayb »

worked great for me. fixed all the times on all existing messages. Thank you!! :D
thetechpub
Registered User
Posts: 18
Joined: Fri May 02, 2003 3:33 pm

Post by thetechpub »

A COMPLETE copy/paste of what you posted, where you posted gave me the following message when attempting to load my boards...

Parse error: parse error in /var/www/html/phpBB2/includes/functions.php on line 375

Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/phpBB2/includes/functions.php:375) in /var/www/html/phpBB2/includes/sessions.php on line 293

Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/phpBB2/includes/functions.php:375) in /var/www/html/phpBB2/includes/sessions.php on line 294


I had to replace the file with the original in order to get the boards to work again...
OmAc Sigyn
Registered User
Posts: 1
Joined: Wed Apr 07, 2004 7:07 pm
Location: Ontario, Canada
Contact:

Post by OmAc Sigyn »

Thanks a bunch, I've been searching for a quick fix like this for awhile now. :D

thetechpub wrote:
A COMPLETE copy/paste of what you posted, where you posted gave me the following message when attempting to load my boards...


thetechpub, I think that you are misunderstanding how to implement this fix ... do not simply replace your entire functions.php file with the code supplied in this post, it sounds like that is exactly what you are doing. As Wysiwygs has explained, you have to look for this function "create_date" within your functions.php file and replace just this section of coding therein with the code provided in this thread. It couldn't be any easier... just follow the directions Wysiwyg posted 2 posts below this one.

As for the confusion as to whether or not this code is actually useful to registered members, I find it is. By changing the default forum time to include DST automatically, all registered members will see the effect of the DST. Previous to this code all of my members had to change their profile timezone from GMT -5 to GMT -4 to accomodate for the daylight savings time change. With this code in place, all times on the forum (including those of registered members) are displayed properly.

Considering how few of a percentage of people are NOT using DST, I think this code is very useful for many forum admins Simply said, if the majority of your users do not observer DST, then don't use the fix :) Personally, all of the users on my forum observe DST, so I'm thankful for this snippit of code.

Thanks again, much appreciated. :D
thetechpub
Registered User
Posts: 18
Joined: Fri May 02, 2003 3:33 pm

Post by thetechpub »

OmAc Sigyn, my last name is not Dumas... I DID do the find/replace of the code as indicated here. AS I stated, uploading the MODIFIED file to the boards (correct directory and all) killed the boards. Re-uploading the non-modified file (I always keep a clean, safe copy of files when making mods) fixed it so that they functioned.

If this file is identical for everyone, could someone send me theirs? I'd give that a shot and see if it works.
User avatar
Mr Material
Registered User
Posts: 46
Joined: Fri Jun 28, 2002 3:52 pm
Location: UK

Post by Mr Material »

The fix as suggested in the first post works very well on my site in the UK..
User avatar
Tux_Rules
Registered User
Posts: 958
Joined: Sat Apr 24, 2004 10:48 pm
Location: Afton, Michigan
Contact:

Post by Tux_Rules »

wysiwygs
Registered User
Posts: 22
Joined: Tue Aug 05, 2003 6:41 am

Post by wysiwygs »

In a word.... No!
DoRullings
Registered User
Posts: 2
Joined: Mon May 24, 2004 2:51 pm

Post by DoRullings »

I've implemented your timesaving mod and it works great here, thanks.

DoRullings
Zypher
Registered User
Posts: 381
Joined: Fri Mar 12, 2004 7:04 am
Location: Australia
Contact:

Post by Zypher »

i have read all the post, and are you saying that it automatically changes it from dst to standard time, or vice versa?
- Zypher

~Beware of the Darkness Within!~

Fully Loaded
safeTsurfa
I've Been Banned!
Posts: 1959
Joined: Sat May 08, 2004 10:21 am
Location: United Kingdom
Contact:

Post by safeTsurfa »

Hmm, a nice attempt, but I would rather keep to UTC/GMT and let the users change it for themselves.

I feel that if the time changes autoimatically for the board to reflect DST that would simply confuse things, the more so as I saw no reference to the "All times are GMT" on the index page and others being changed to "All times are Daylight Savings"

Also, given the inconsistent start dates for DST between that lot in the Americas and us lot in the UK or Europe, that will again cause confusion, some bright spark from over there is sure to chime in with "but it isn't DST for another week yet!".

I think the next logical step is to advance this so that it checks the user's profile and adjusts for them personally as they log in? To do this it would probably need a note in the Date Explain telling them not to adjust for DST as the board will do it automatically for them, so they adjust their zone in base GMT.
safeTsurfa
Need help? First READ THIS
Personal projects: My Mods
Locked

Return to “[2.0.x] MODs in Development”