[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.
sjfierce
Registered User
Posts: 45
Joined: Tue Jun 15, 2004 11:10 am

Post by sjfierce »

I'm in the UK (along with 99% of my users) and this little mod seems to do the trick. Especially useful since I'm using the Topic Calendar which shows different times if my users forget to update their timezone.

One small issue - the time I last logged in is out by an hour. I'm using Categories Hierarchy 2.1.1 so this may be an issue with this. Does anyone else have the same problem?
User avatar
webmacster87
Former Team Member
Posts: 3758
Joined: Fri Jun 11, 2004 2:30 am
Location: San Mateo, CA
Name: Douglas Bell
Contact:

Post by webmacster87 »

Note: I was working on my new MOD, DST Management, when I stumbled upon this topic.

I don't know how you all are getting this MOD to work. Based on what I see within the topic, all this MOD does is edit includes/functions.php to add 1 hour to the default time that is generated. In most cases, this is virtually useless, as it affects all users, regardless of whether or not they observe Daylight Savings Time, and, when Daylight Savings Time ends, you have to uninstall this MOD.

Ptirhiik's Profile Control Panel gets it right--among other features, an option is added to the profile asking if you observe Daylight Savings Time at present--Yes adds 1 hour to the outputted time, No sets no effect.
User avatar
Brian Hamilton
Registered User
Posts: 9
Joined: Sat Nov 06, 2004 6:09 pm
Location: Los Angeles, CA
Contact:

Post by Brian Hamilton »

I just installed the mod --and it works GREAT for me as 99% of my users are from the continental USA and all observe daylight savings. If anyone else has a problem with the time setting, they can adjust it in their profile. As far as I'm concerned, sorry: majority rules until there's a better fix :)

Thanks for the mod :D
User avatar
Quimbly
Registered User
Posts: 123
Joined: Tue May 17, 2005 5:56 pm

*** PLEASE HELP!!! ***

Post by Quimbly »

This mod is exactly the kind of thing I'm looking for...

Unfortunately, it doesn't work for me. I'm hosted at GoDaddy, which as I recently learn is located in Arizona. From reading this thread I learned that Arizon is one of the few states that does NOT observe Daylight Savings Time (DST).

I am located in Alberta, where we DO observe DST. My phpBB community is a local one for Calgary, so I don't care much for users that are not in our timezone. By that, I mean users outside of our timezone can adjust their profile time zone setting to whatever they want, in order to see correct post times. I just want the typical user signing up to see the correct post time for Calgary, Alberta, taking into account DST. And of course, I want it to work such that if they select GMT-7 (Alberta's Timezone), that they'll see the correct time, without having to change this setting when DST takes place.

Can anyone suggest something in particular that is easy and will work in this case?
Paddic
Registered User
Posts: 198
Joined: Tue May 18, 2004 10:58 am

Re: *** PLEASE HELP!!! ***

Post by Paddic »

Quimbly wrote: Can anyone suggest something in particular that is easy and will work in this case?

You have to know, when is the first day of daylight saving time, and when is the last day.

After you know these dates, modify the mod this way:

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

replace with:
$dst = intval(date('m', $gmepoch) . date('d', $gmepoch));
$dst = ($dst >= M1D1 && $dst <= M2D2) ? 3600 : 0;

M1D1 and M2D2 gets replaced by numbers representing the first date and last date of daylight saving time. For example, if daylight saving starts first of April and ends 15th of October, then M1D1 is 401 and M2D2 is 1015:

$dst = ($dst >= 401 && $dst <= 1015) ? 3600 : 0;

I did not test this code, so it might contain typos and it might not work at all to start with...
User avatar
Quimbly
Registered User
Posts: 123
Joined: Tue May 17, 2005 5:56 pm

Post by Quimbly »

Ok, well, I kind of took your suggestion. My way is definately not the most elegant, but at least it appears to work.

I found out that in Alberta, DST switches take place during the first Sunday of April and October. So, in case anyone is in the same situation as me (webhost in a non-DST zone -- e.g. GoDaddy, but community is in a DST zone), I believe this code will work (assuming your area uses the same DST switch dates as Alberta does):

Code: Select all

	// n = Numeric month, without leading zero
	// w = Numeric representation of the day of the week (0 = sunday)
	// j = Numeric day of the month without leading zeros
	// G = 24-hour format for hour, without leading zeros
	$dst_date = date("n w j G");	
	list($month, $day_of_week, $day, $hour) = split(' ', $dst_date);

	// Winter months (January, February, March, November, December)
	if ($month == 1 || $month == 2 || $month == 3 || $month == 11 || $month == 12)
	{
		$dst = 0;
	}
	// Summer months (May, June, July, August, September)
	if ($month == 5 || $month == 6 || $month == 7 || $month == 8 || $month == 9)
	{
		$dst = 3600;
	}
	// Borderline months
	if ($month == 4)	// April
	{
		if ($day < 8)	// First week
		{
			if ($day_of_week == 0)	// Sunday
			{
				if ($hour < 2)	// Before 2 AM
				{
					$dst = 0;
				}
				else
				{
					$dst = 3600;
				}
			}
			else
			{
				// Number of days until the next Sunday
				$diff = 7 - $day_of_week;

				// If today's current day plus the number of days 
				// until the next Sunday is greater than 7, 
				// then the first sunday of the month has already
				// past
				if ($diff + $day < 7)	
				{
					$dst = 0;
				}
				else	// before the first Sunday
				{
					$dst = 3600;					
				}
			}
		}
		else		// After first week
		{
			$dst = 3600;
		}
	}
	if ($month == 10)	// October
	{
		if ($day < 8)	// First week
		{
			if ($day_of_week == 0)	// Sunday
			{
				if ($hour < 2)	// Before 2 AM
				{
					$dst = 3600;
				}
				else
				{
					$dst = 0;
				}
			}
			else
			{
				// Number of days until the next Sunday
				$diff = 7 - $day_of_week;	

				// If today's current day plus the number of days
				// until the next Sunday is greater than 7, 
				// then the first sunday of the month has already 
				// past
				if ($diff + $day < 7)	
				{
					$dst = 3600;
				}
				else	// before the first Sunday
				{
					$dst = 0;					
				}
			}
		}
		else		// After first week
		{
			$dst = 0;
		}
	}

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

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

Re: *** PLEASE HELP!!! ***

Post by wysiwygs »

Paddic wrote: M1D1 and M2D2 gets replaced by numbers representing the first date and last date of daylight saving time.

The main difficulty that I see with this is the annual maintenance that this will require. At present, DST starts on the first Sunday in April and ends on the last Sunday in October (see: http://webexhibits.org/daylightsaving/b.html). Of course, this could be coded into the fix.

My suggestion to Quimbly is to move to a different Host company. There are several very good Host companies other than Godaddy at a lesser annual hosting rate.
Last edited by wysiwygs on Fri Jun 17, 2005 2:30 pm, edited 2 times in total.
wysiwygs
Registered User
Posts: 22
Joined: Tue Aug 05, 2003 6:41 am

Post by wysiwygs »

Fountain of Apples wrote: I don't know how you all are getting this MOD to work. ... In most cases, this is virtually useless, as it affects all users, regardless of whether or not they observe Daylight Savings Time, and, when Daylight Savings Time ends, you have to uninstall this MOD.

I am not sure if I was meant to laugh or cry from this... Either this was written with tongue in cheek or you are new to PHP. If you go back to the very first posting of this topic and follow the links in the posting, you should end up with a better understanding of how this FIX works. In addition, as stated and restated, this FIX is based on the belief that a site's forums are a destination. As a destination, the user (e.g. you or me) goes "to" the forums.... the forums do not come to the user.

No... the FIX does not need to be uninstalled when Daylight Saving Time ends (see: http://www.php.net/manual/en/function.date.php).
newcastlefishing.com
Registered User
Posts: 228
Joined: Sun May 08, 2005 4:57 am

Post by newcastlefishing.com »

ok i just installed the code for daylight saving but it didnt do anything for me, i just realised that the server is not in daylight saving mode they are still 1 hour behind, so is there a way to fix this that i can add 1 hour to the server in the code to reconise the time zone im in.

cheers
User avatar
Ricky_Racer
Registered User
Posts: 609
Joined: Wed Feb 12, 2003 10:02 pm

Post by Ricky_Racer »

From the what it's worth department, in the mind of me :lol:
This is what I used

Code: Select all

#
#-----[ SQL ]-------------------------------------------------
#
ALTER TABLE phpbb_users ADD user_summer_time TINYINT(1) UNSIGNED DEFAULT '0' NOT NULL;
INSERT INTO phpbb_config (config_name, config_value) VALUES ('summer_time','0');
#
#-----[ OPEN ]------------------------------------------------
#
common.php
#
#-----[ FIND ]------------------------------------------------
# 
while ( $row = $db->sql_fetchrow($result) )
{
	$board_config[$row['config_name']] = $row['config_value'];
}
#
#-----[ AFTER, ADD ]------------------------------------------
#
// BEGIN ADD: - MOD - DST
if ( $board_config['summer_time'] != date('I') )
{
	$board_config['summer_time'] = date('I');
}
// END ADD: - MOD - DST
#
#-----[ OPEN ]------------------------------------------------
#
includes/functions.php
#
#-----[ FIND ]------------------------------------------------
#
	static $translate;
#
#-----[ AFTER, ADD ]------------------------------------------
#
	// BEGIN ADD: - MOD - DST
	global $userdata, $db;
	if ( !isset($board_config['summer_time']) )
	{
		$board_config['summer_time'] = false;
		$sql = "INSERT INTO " . CONFIG_TABLE . " (config_name,config_value) VALUES('summer_time','0')";
		if ( !($result = $db->sql_query($sql)) ) message_die(GENERAL_ERROR, 'Could not add key summer_time in config table', '', __LINE__, __FILE__, $sql);
	}
	$switch_summer_time = ( $userdata['user_summer_time'] && $board_config['summer_time'] ) ? true : false;
	if ($switch_summer_time) $tz++;
	// END ADD: - MOD - DST
#
#-----[ OPEN ]------------------------------------------------
#
includes/usercp_register.php
#
#-----[ FIND ]------------------------------------------------
#
	$popup_pm = ( isset($HTTP_POST_VARS['popup_pm']) ) ? ( ($HTTP_POST_VARS['popup_pm']) ? TRUE : 0 ) : TRUE;
#
#-----[ AFTER, ADD ]------------------------------------------
#
	$summer_time = ( isset($HTTP_POST_VARS['summer_time']) ) ? ( ($HTTP_POST_VARS['summer_time']) ? TRUE : 0 ) : TRUE;
#
#-----[ FIND ]------------------------------------------------
#
	$user_timezone = ( isset($HTTP_POST_VARS['timezone']) ) ? doubleval($HTTP_POST_VARS['timezone']) : $board_config['board_timezone'];
#
#-----[ AFTER, ADD ]------------------------------------------
#
	$user_summer_time = ( isset($HTTP_POST_VARS['summer_time']) ) ? doubleval($HTTP_POST_VARS['summer_time']) : $board_config['board_timezone'];
#
#-----[ FIND ]------------------------------------------------
#
			$sql = "UPDATE " . USERS_TABLE . "
				SET " . $username_sql . $passwd_sql . "user_email = '" . str_replace("\'", "''", $email) ."', user_icq = '" . str_replace("\'", "''", $icq) . "', user_website = '" . str_replace("\'", "''", $website) . "', user_occ = '" . str_replace("\'", "''", $occupation) . "', user_from = '" . str_replace("\'", "''", $location) . "', user_interests = '" . str_replace("\'", "''", $interests) . "', user_sig = '" . str_replace("\'", "''", $signature) . "', user_sig_bbcode_uid = '$signature_bbcode_uid', user_viewemail = $viewemail, user_aim = '" . str_replace("\'", "''", str_replace(' ', '+', $aim)) . "', user_yim = '" . str_replace("\'", "''", $yim) . "', user_msnm = '" . str_replace("\'", "''", $msn) . "', user_attachsig = $attachsig, user_allowsmile = $allowsmilies, user_allowhtml = $allowhtml, user_allowbbcode = $allowbbcode, user_allow_viewonline = $allowviewonline, user_notify = $notifyreply, user_notify_pm = $notifypm, user_popup_pm = $popup_pm, user_timezone = $user_timezone, user_dateformat = '" . str_replace("\'", "''", $user_dateformat) . "', user_lang = '" . str_replace("\'", "''", $user_lang) . "', user_style = $user_style, user_active = $user_active, user_actkey = '" . str_replace("\'", "''", $user_actkey) . "'" . $avatar_sql . "
#
#-----[ INLINE FIND ]-----------------------------------------
#
, user_timezone = $user_timezone
#
#-----[ INLINE AFTER, ADD ]-----------------------------------
#
, user_summer_time = $user_summer_time
#
#-----[ FIND ]------------------------------------------------
#
			$sql = "INSERT INTO " . USERS_TABLE . "	(user_id, username, user_regdate, user_password, user_email, user_icq, user_website, user_occ, user_from, user_interests, user_sig, user_sig_bbcode_uid, user_avatar, user_avatar_type, user_viewemail, user_aim, user_yim, user_msnm, user_attachsig, user_allowsmile, user_allowhtml, user_allowbbcode, user_allow_viewonline, user_notify, user_notify_pm, user_popup_pm, user_timezone, user_dateformat, user_lang, user_style, user_level, user_allow_pm, user_active, user_actkey)
				VALUES ($user_id, '" . str_replace("\'", "''", $username) . "', " . time() . ", '" . str_replace("\'", "''", $new_password) . "', '" . str_replace("\'", "''", $email) . "', '" . str_replace("\'", "''", $icq) . "', '" . str_replace("\'", "''", $website) . "', '" . str_replace("\'", "''", $occupation) . "', '" . str_replace("\'", "''", $location) . "', '" . str_replace("\'", "''", $interests) . "', '" . str_replace("\'", "''", $signature) . "', '$signature_bbcode_uid', $avatar_sql, $viewemail, '" . str_replace("\'", "''", str_replace(' ', '+', $aim)) . "', '" . str_replace("\'", "''", $yim) . "', '" . str_replace("\'", "''", $msn) . "', $attachsig, $allowsmilies, $allowhtml, $allowbbcode, $allowviewonline, $notifyreply, $notifypm, $popup_pm, $user_timezone, '" . str_replace("\'", "''", $user_dateformat) . "', '" . str_replace("\'", "''", $user_lang) . "', $user_style, 0, 1, ";
#
#-----[ INLINE FIND ]-----------------------------------------
#
, user_timezone
#
#-----[ INLINE AFTER, ADD ]-----------------------------------
#
, user_summer_time
#
#-----[ INLINE FIND ]-----------------------------------------
#
, $user_timezone
#
#-----[ INLINE AFTER, ADD ]-----------------------------------
#
, $user_summer_time
#
#-----[ FIND ]------------------------------------------------
#
	$user_timezone = $userdata['user_timezone'];
#
#-----[ AFTER, ADD ]------------------------------------------
#
	$user_summer_time = $userdata['user_summer_time'];
#
#-----[ FIND ]------------------------------------------------
#
		'L_EMAIL_ADDRESS' => $lang['Email_address'],
#
#-----[ AFTER, ADD ]------------------------------------------
#
		'L_SUMMER_TIME' => $lang['summer_time'],
		'SUMMER_TIME_YES' => ( $user_summer_time ) ? 'checked="checked"' : '',
		'SUMMER_TIME_NO' => ( !$user_summer_time ) ? 'checked="checked"' : '',
#
#-----[ OPEN ]------------------------------------------------
#
admin/admin_board.php
#
#-----[ FIND ]------------------------------------------------
#
$timezone_select = tz_select($new['board_timezone'], 'board_timezone');
#
#-----[ AFTER, ADD ]------------------------------------------
#
$summer_time_yes = ( $new['summer_time'] ) ? "checked=\"checked\"" : "";
$summer_time_no  = (!$new['summer_time'] ) ? "checked=\"checked\"" : "";
#
#-----[ FIND ]------------------------------------------------
#
	"TIMEZONE_SELECT" => $timezone_select,
#
#-----[ AFTER, ADD ]------------------------------------------
#
	"L_SUMMER_TIME" => $lang['summer_time_set'],
	"SUMMER_TIME_YES" => $summer_time_yes,
	"SUMMER_TIME_NO" => $summer_time_no,
#
#-----[ OPEN ]------------------------------------------------
#
language/lang_english/lang_admin.php
#
#-----[ FIND ]------------------------------------------------
#
$lang['System_timezone'] = 'System Timezone';
#
#-----[ AFTER, ADD ]------------------------------------------
#
$lang['summer_time_set'] = 'Adjust for daylight savings time ? (add +1 hour to local time)';
#
#-----[ OPEN ]------------------------------------------------
#
language/lang_english/lang_main.php
#
#-----[ FIND ]------------------------------------------------
#
$lang['Timezone'] = 'Timezone';
#
#-----[ AFTER, ADD ]------------------------------------------
#
$lang['summer_time'] = 'Are you in a daylight savings timezone ?';
#
#-----[ OPEN ]------------------------------------------------
#
templates/subSilver/admin/board_config_body.tpl
#
#-----[ FIND ]------------------------------------------------
#
	<tr>
		<td class="row1">{L_SYSTEM_TIMEZONE}</td>
		<td class="row2">{TIMEZONE_SELECT}</td>
	</tr>
#
#-----[ AFTER, ADD ]------------------------------------------
#
	<tr>
		<td class="row1">{L_SUMMER_TIME}</td>
		<td class="row2"><input type="radio" name="summer_time" value="1" {SUMMER_TIME_YES} /> {L_YES}&nbsp;&nbsp;<input type="radio" name="summer_time" value="0" {SUMMER_TIME_NO} /> {L_NO}</td>
	</tr>
#
#-----[ OPEN ]------------------------------------------------
#
templates/subSilver/profile_add_body.tpl
#
#-----[ FIND ]------------------------------------------------
#
	<tr>
	  <td class="row1"><span class="gen">{L_TIMEZONE}:</span></td>
	  <td class="row2"><span class="gensmall">{TIMEZONE_SELECT}</span></td>
	</tr>
#
#-----[ AFTER, ADD ]------------------------------------------
#
	<tr>
	  <td class="row1"><span class="gen">{L_SUMMER_TIME}</span></td>
	  <td class="row2">
		<input type="radio" name="summer_time" value="1" {SUMMER_TIME_YES} />
		<span class="gen">{L_YES}</span>&nbsp;&nbsp;
		<input type="radio" name="summer_time" value="0" {SUMMER_TIME_NO} />
		<span class="gen">{L_NO}</span></td>
	</tr>
#
#------[ SAVE/CLOSE/UPLOAD/ENJOY !!! ---------------------------------------------------
#
# -= END =-
It did change back when we went off of DST last month.
More from the what it's worth department I don't think anybody cared post 1 and post 2
User avatar
MHobbit
Former Team Member
Posts: 4761
Joined: Thu Mar 18, 2004 5:32 pm
Location: There and Back Again

Post by MHobbit »

Other than having a wrong topic prefix, the original author who posted this "fix" hasn't been here since July 7, 2003. Two years ago! So, I'm going to lock this topic...

If someone can/wants to use the MOD Template and make a MOD out of this, feel free to, but try contacting the original topic starter...
Former phpBB MOD Team member
No private support is offered.
"There’s too many things to get done, and I’m running out of days..."
Locked

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