[RELEASE] DST MOD (daylight savings 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.
blulegend
Registered User
Posts: 83
Joined: Wed Jan 30, 2002 5:41 pm

[RELEASE] DST MOD (daylight savings time)

Post by blulegend »

This is what I'm sending everyone:

Here's the link that I have uploaded to this site.

Please let me know if it works out for you.

http://www.phpbb.com/mods/downloads/upl ... d_copy.txt

Seems to be working for everyone that had asked so here it is.

UPDATE: the link is down since it was on the dead server, here's the code:

Code: Select all

################################################################# 
## Mod Title:    Daylight Savings Time (DST) MOD 
## Mod Version:  1.1.0 
## Author:       blulegend 
## Description:  Allows users to turn DST on/off.
##               Allows admin to change user settings as well.
##               Current mode reflected in timezone text on each page.
##               No table modification required! :)
## 
## Installation Level:  Moderately Easy. 
## Installation Time:   15-30 Minutes 
## Files To Edit:       9 
## Included Files:      None 
################################################################# 
## Security Disclaimer: This MOD Cannot Be Posted To Or Added At Any Non-Official phpBB Sites 
################################################################# 
## 
## Author Note: 
## Simply make an announcement for users to change this option in their profiles.
## If you know MYSQL well enough you could change the settings for all users in certain timezones
## for them by making a simple query.
##
## IMPORTANT!!: Line numbers are for reference only so you can find the code faster.
##              DO NOT RELY ON LINE NUMBERS ONLY.
##              WATCH OUT FOR AFTER AND BEFORE ADDITIONS
##              I HAVE TRIED TO LIMIT REPLACE ACTIONS AS MUCH AS POSSIBLE
## 
################################################################# 
## Before Adding This MOD To Your Forum, You Should Back Up All Files Related To This MOD 
################################################################# 
#
#-----[ OPEN /admin/admin_users.php ]------------------------------
# 

#
#-----[ FIND around line 100 ]-----------------------------------
# 

		$attachsig = ( isset( $HTTP_POST_VARS['attachsig']) ) ? ( ( $HTTP_POST_VARS['attachsig'] ) ? TRUE : 0 ) : 0;

# 
#-----[ AFTER, ADD ]-------------------------------------------
#

		$dstime = ( isset($HTTP_POST_VARS['dstime']) ) ? ( ($HTTP_POST_VARS['dstime']) ? TRUE : 0 ) : 0; // DST MOD

#
#-----[ FIND around line 543 ]-----------------------------------
# 

		if( !$error )
		{
			if( $HTTP_POST_VARS['deleteuser'] )


# 
#-----[ BEFORE, ADD ]-------------------------------------------
# 

		if ( $dstime ) $user_timezone += 50; // DST MOD


#
#-----[ FIND around line 775 ]-----------------------------------
# 

		$viewemail = $this_userdata['user_viewemail'];
		$notifypm = $this_userdata['user_notify_pm'];

# 
#-----[ BEFORE, ADD ]-------------------------------------------
# 

		$dstime = ( $userdata['user_timezone'] > 12 ) ? true : 0; // DST MOD

#
#-----[ FIND around line 790 ]-----------------------------------
# 

		$user_timezone = $userdata['user_timezone'];

# 
#-----[ REPLACE WITH ]-------------------------------------------
# 

		// OLD $user_timezone = $userdata['user_timezone'];
		$user_timezone = ( $userdata['user_timezone'] > 12 ) ? $userdata['user_timezone'] - 50 : $userdata['user_timezone']; // DST MOD

#
#-----[ FIND around line 900 ]-----------------------------------
# 

			$s_hidden_fields .= '<input type="hidden" name="signature" value="' . str_replace("\"", """, $signature) . '" />';
			$s_hidden_fields .= '<input type="hidden" name="viewemail" value="' . $viewemail . '" />';

# 
#-----[ BEFORE, ADD ]-------------------------------------------
# 

			$s_hidden_fields .= '<input type="hidden" name="dstime" value="' . $dstime . '" />'; // DST MOD

#
#-----[ FIND around line 900 ]-----------------------------------
# 

			'L_DELETE_USER' => $lang['User_delete'],
			'L_DELETE_USER_EXPLAIN' => $lang['User_delete_explain'],
			'L_SELECT_RANK' => $lang['Rank_title'],

# 
#-----[ AFTER, ADD ]-------------------------------------------
# 

			// DST MOD
			'DSTIME_YES' => ( $dstime ) ? 'checked="checked"' : '',
			'DSTIME_NO' => ( !$dstime ) ? 'checked="checked"' : '',

			'L_DSTIME' => $lang['Daylight_savings_time'], 
			'L_DSTIME_EXPLAIN' => $lang['Daylight_savings_time_explain'],
			// END MOD


#
#-----[ OPEN /includes/functions.php ]------------------------------
# 

#
#-----[ FIND around line 90 ]-----------------------------------
# 

	return ( $row = $db->sql_fetchrow($result) ) ? $row : false;

# 
#-----[ REPLACE WITH ]-------------------------------------------
#

	// DST MOD
	// OLD return ( $row = $db->sql_fetchrow($result) ) ? $row : false;
	if ( $row = $db->sql_fetchrow($result) )
	{
		if ( $row['user_timezone'] > 12 ) $row['user_timezone'] -= 50;
		return $row;
	}
	else
	{
		return false;
	}
	// END MOD

#
#-----[ FIND around line 212 ]-----------------------------------
# 

		if ( isset($userdata['user_timezone']) )
		{

# 
#-----[ AFTER, ADD ]-------------------------------------------
#

			// DST MOD
			if ( $userdata['user_timezone'] > 12 )
			{
				$userdata['user_timezone'] = strval($userdata['user_timezone'] - 50);
				$board_config['dstime'] = true;
			}
			// END MOD

#
#-----[ FIND around line 329 ]-----------------------------------
# 

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

# 
#-----[ BEFORE, ADD ]-------------------------------------------
#

	if ( $board_config['dstime'] ) $tz++; // DST MOD

#
#-----[ OPEN /includes/usercp_avatar.php ]------------------------------
# 

#
#-----[ FIND around line 236 ]-----------------------------------
# 

&$language, &$timezone, &$dateformat)

# 
#-----[ REPLACE WITH ]-------------------------------------------
#

&$language, &$timezone, &$dateformat, &$dstime) // DST MOD

#
#-----[ FIND around line 312 ]-----------------------------------
# 

'language', 'timezone', 'dateformat');

# 
#-----[ REPLACE WITH ]-------------------------------------------
#

'language', 'timezone', 'dateformat', 'dstime'); // DST MOD


#
#-----[ OPEN /includes/page_header.php ]------------------------------
# 

#
#-----[ FIND around line 500 ]-----------------------------------
# 

	'S_TIMEZONE' => sprintf($lang['All_times'], $lang[$board_config['board_timezone']]),

# 
#-----[ REPLACE WITH ]-------------------------------------------
#

	// OLD 'S_TIMEZONE' => sprintf($lang['All_times'], $lang[$board_config['board_timezone']]),
	'S_TIMEZONE' => sprintf($lang['All_times'], $lang[$board_config['board_timezone']]) . (( $board_config['dstime'] ) ? ' ' . $lang['DST_TEXT'] : ''), // DST MOD

#
#-----[ OPEN /includes/usercp_register.php ]------------------------------
# 

#
#-----[ FIND around line 126 ]-----------------------------------
# 

	$notifypm = ( isset($HTTP_POST_VARS['notifypm']) ) ? ( ($HTTP_POST_VARS['notifypm']) ? TRUE : 0 ) : TRUE;
	$popuppm = ( isset($HTTP_POST_VARS['popup_pm']) ) ? ( ($HTTP_POST_VARS['popup_pm']) ? TRUE : 0 ) : TRUE;

# 
#-----[ AFTER, ADD ]-------------------------------------------
#

	$dstime = ( isset($HTTP_POST_VARS['dstime']) ) ? ( ($HTTP_POST_VARS['dstime']) ? TRUE : 0 ) : 0; // DST MOD

#
#-----[ FIND around line 385 ]-----------------------------------
# 

	if ( !$error )
	{
		if ( $avatar_sql == '' )

# 
#-----[ BEFORE, ADD ]-------------------------------------------
#

	if ( $dstime ) $user_timezone += 50; // DST MOD

#
#-----[ FIND around line 668 ]-----------------------------------
# 

	$viewemail = $userdata['user_viewemail'];
	$notifypm = $userdata['user_notify_pm'];

# 
#-----[ BEFORE, ADD ]-------------------------------------------
#

	$dstime = ( $userdata['user_timezone'] > 12 ) ? true : 0; // DST MOD

#
#-----[ FIND around line 683 ]-----------------------------------
# 

	$user_timezone = $userdata['user_timezone'];

# 
#-----[ REPLACE WITH ]-------------------------------------------
#

	// OLD $user_timezone = $userdata['user_timezone'];
	$user_timezone = ( $userdata['user_timezone'] > 12 ) ? $userdata['user_timezone'] - 50 : $userdata['user_timezone']; // DST MOD

#
#-----[ FIND around line 713 ]-----------------------------------
# 

$user_lang, $user_timezone, $user_dateformat);

# 
#-----[ REPLACE WITH ]-------------------------------------------
#

$user_lang, $user_timezone, $user_dateformat, $dstime); // DST MOD

#
#-----[ FIND around line 836 ]-----------------------------------
# 

		'L_CURRENT_PASSWORD' => $lang['Current_password'], 
		'L_NEW_PASSWORD' => ( $mode == 'register' ) ? $lang['Password'] : $lang['New_password'], 

# 
#-----[ BEFORE, ADD ]-------------------------------------------
#

		// DST MOD
		'L_DSTIME' => $lang['Daylight_savings_time'], 
		'L_DSTIME_EXPLAIN' => $lang['Daylight_savings_time_explain'],

		'DSTIME_YES' => ( $dstime ) ? 'checked="checked"' : '',
		'DSTIME_NO' => ( !$dstime ) ? 'checked="checked"' : '',
		// END MOD


#
#-----[ OPEN /language/lang_xxx/lang_admin.php ]------------------------------
# 

#
#-----[ FIND around line 700 ]-----------------------------------
# 

//
// That's all Folks!
// -------------------------------------------------

# 
#-----[ BEFORE, ADD ]-------------------------------------------
#

// DST MOD
$lang['Daylight_savings_time'] = "Daylight Savings Time";
$lang['Daylight_savings_time_explain'] = "Selecting yes will advance all times by 1 hour";
//

#
#-----[ OPEN /language/lang_xxx/lang_main.php ]------------------------------
# 

#
#-----[ FIND around line 980 ]-----------------------------------
# 

//
// That's all Folks!
// -------------------------------------------------

# 
#-----[ BEFORE, ADD ]-------------------------------------------
#

// DST MOD
$lang['Daylight_savings_time'] = "Daylight Savings Time";
$lang['Daylight_savings_time_explain'] = "Selecting yes will advance all times by 1 hour";
$lang['DST_TEXT'] = "DST +1";
//

#
#-----[ OPEN /templates/subSilver/admin/user_edit_body.tpl ]------------------------------
# 

#
#-----[ FIND around line 207 ]-----------------------------------
# 

	<tr> 
	  <td class="row1"><span class="gen">{L_TIMEZONE}</span></td>
	  <td class="row2">{TIMEZONE_SELECT}</td>
	</tr>

# 
#-----[ AFTER, ADD ]-------------------------------------------
#

	<!-- DST MOD begin -->
	<tr> 
	  <td class="row1"><span class="gen">{L_DSTIME}:</span><br /><span class="gensmall">{L_DSTIME_EXPLAIN}</span></td>
	  <td class="row2"> 
		<input type="radio" name="dstime" value="1" {DSTIME_YES} />
		<span class="gen">{L_YES}</span>&nbsp;&nbsp; 
		<input type="radio" name="dstime" value="0" {DSTIME_NO} />
		<span class="gen">{L_NO}</span></td>
	</tr>
	<!-- DST MOD end -->

#
#-----[ OPEN /templates/subSilver/profile_add_body.tpl ]------------------------------
# 

#
#-----[ FIND around line 216 ]-----------------------------------
# 

	<tr> 
	  <td class="row1"><span class="gen">{L_TIMEZONE}:</span></td>
	  <td class="row2"><span class="gensmall">{TIMEZONE_SELECT}</span></td>
	</tr>

# 
#-----[ AFTER, ADD ]-------------------------------------------
#

	<!-- DST MOD begin -->
	<tr> 
	  <td class="row1"><span class="gen">{L_DSTIME}:</span><br /><span class="gensmall">{L_DSTIME_EXPLAIN}</span></td>
	  <td class="row2"> 
		<input type="radio" name="dstime" value="1" {DSTIME_YES} />
		<span class="gen">{L_YES}</span>&nbsp;&nbsp; 
		<input type="radio" name="dstime" value="0" {DSTIME_NO} />
		<span class="gen">{L_NO}</span></td>
	</tr>
	<!-- DST MOD end -->

# 
#-----[ SAVE/CLOSE ALL FILES ]-----------------------------------
# EoM
Last edited by blulegend on Tue Apr 30, 2002 9:10 am, edited 2 times in total.
blulegend
Registered User
Posts: 83
Joined: Wed Jan 30, 2002 5:41 pm

Post by blulegend »

If you try it, please let me know if it works ok.
User avatar
morpheus2matrix
Former Team Member
Posts: 9171
Joined: Wed Apr 10, 2002 7:31 pm
Location: France
Contact:

Post by morpheus2matrix »

i think it's a good idea but : what is DST ??
Former phpBB MOD-Team Member -

Forgive my bad English :(

No support by PM/Email - Thanks - You can thanks me here :) - Pay me for installing MOD's :lol:
steveurkel
Registered User
Posts: 33
Joined: Thu Apr 11, 2002 6:59 am
Location: Munich
Contact:

The answer

Post by steveurkel »

morpheus2matrix wrote: what is DST ??


DST = Daylight Savings Time 8)
[H-c] Riva
Registered User
Posts: 16
Joined: Thu Apr 11, 2002 10:14 am
Location: NRW / Germany
Contact:

Post by [H-c] Riva »

This stupid "Daylight Savings Time" thing. Set the Clock 1 Hour forward in Summer.
'Fate, it seems, is not without a sense of irony'  -Wachowski Brothers
User avatar
morpheus2matrix
Former Team Member
Posts: 9171
Joined: Wed Apr 10, 2002 7:31 pm
Location: France
Contact:

Post by morpheus2matrix »

ok
thx
Former phpBB MOD-Team Member -

Forgive my bad English :(

No support by PM/Email - Thanks - You can thanks me here :) - Pay me for installing MOD's :lol:
xamot
Registered User
Posts: 13
Joined: Mon Apr 15, 2002 4:15 am
Location: St. Louis, Mo, USA

Post by xamot »

blulegend wrote: If you try it, please let me know if it works ok.


blulegend:

Thanks for PMing it to me earlier. I ended up hacking my own system that takes ideas from your MOD and from chris109's (http://www.phpbb.com/phpBB/viewtopic.php?t=12810)

I didn't want to make it so users would have to remember to turn on DST each spring and fall nor did I want to turn each one on/off individually. So rather than add 50 to the timezone if they have their flag on. I added timezones that are offset by 50. If they are using one of these timezones AND the board has DST turned on they get summer times. I'd post what I did but I think it would be more productive to discuss a full-featured timezone MOD. I've given it quite a bit of thought and have some ideas on how to do it. I think it would be pretty simple and very flexible. I still need to work out the conversion formula. Once I do that I'll probably post what I'm working on.

Does anyone know if a better timezone system is being worked on for 2.2? If so who should I talk to so I don't go duplicating work?
Last edited by xamot on Thu Apr 18, 2002 3:28 pm, edited 2 times in total.
User avatar
heretic
Registered User
Posts: 33
Joined: Mon Mar 25, 2002 4:38 am

Works

Post by heretic »

Thanks. It works ok on my board
blulegend
Registered User
Posts: 83
Joined: Wed Jan 30, 2002 5:41 pm

Post by blulegend »

xamot wrote: blulegend:

Thanks for PMing it to me earlier. I ended up hacking my own system that takes ideas from your MOD and from chris109's (http://www.phpbb.com/phpBB/viewtopic.php?t=12810)

I didn't want to make it so users would have to remember to turn on DST each spring and fall nor did I want to turn each one on/off individually. So rather than add 50 to the timezone if they have their flag on. I added timezones that are offset by 50. If they are using one of these timezones AND the board has DST turned on they get summer times. I'd post what I did but I think it would be more productive to discuss a full-featured timezone MOD. I've given it quite a bit of thought and have some ideas on how to do it. I think it would be pretty simple and very flexible. I still need to work out the conversion formula. Once I do that I'll probably post what I'm working on.

Does anyone know if a better timezone system is being worked on for 2.2? If so who should I talk to so I don't go duplicating work?

I thought about that. But not all timezones switch to daylight savings time at the same time. So I couldn't find any other simple way than to make it user-selectable. I thought about finding out which day exactly each timezone would change over (ie. 2nd Sunday in April, etc.) and have it check, but that would require lots of checking.
xamot
Registered User
Posts: 13
Joined: Mon Apr 15, 2002 4:15 am
Location: St. Louis, Mo, USA

Post by xamot »

blulegend wrote: I thought about that. But not all timezones switch to daylight savings time at the same time. So I couldn't find any other simple way than to make it user-selectable. I thought about finding out which day exactly each timezone would change over (ie. 2nd Sunday in April, etc.) and have it check, but that would require lots of checking.


Yup. Once I work out the function (hopefully I'll get some time soon to make it) the most difficult part would be getting a basic list of Timezones with DST start and end times. My data structure currently is...

Code: Select all

$timezone['timezone-id']['name'] = "xxx";
$timezone['timezone-id']['short_name'] = "xxx";
$timezone['timezone-id']['raw_offset'] = "xx';   // raw offset from GMT/UTC
$timezone['timezone-id']['dst_savings'] = "xx";  // adjustment amount (precision?)
$timezone['timezone-id']['start_month'] = "xx";
$timezone['timezone-id']['start_day'] = "xx";
$timezone['timezone-id']['start_day_of_week'] = "xx";  // used for "First Sunday of" logic
$timezone['timezone-id']['start_hour'] = "xx";
$timezone['timezone-id']['start_mode'] = "xx"; // indicates using exact day, day of week, or ???
$timezone['timezone-id']['end_month'] = "xx";
$timezone['timezone-id']['end_day'] = "xx";
$timezone['timezone-id']['end_hour'] = "xx";
$timezone['timezone-id']['end_day_of_week'] = "";
$timezone['timezone-id']['end_mode'] = "xx";
I probably also need some kind if indicator if the start (or end) values are in GMT/UTC or adjusted for rawoffset already. I might assume that they are for now. I'll also need to setup a bunch of constants. But like I said I think if I can figure out a conversion function everything else is cake. I need to find some more resouces on dst conversions...

If anyone knows a gpl'ed program that has a timezone localization algorithm that I could borrow that would save a lot of time.
Narf_
Registered User
Posts: 68
Joined: Sun Mar 17, 2002 6:09 pm
Location: Netherlands
Contact:

Post by Narf_ »

When I turn DTS ON; then the last visit section in the memberlist is 2 days and 2 hours ahead, this also happend to the 'who's online' on the index (so nobody visited the board today :?)

Is there something I must change to the lastvisit MOD ?
Shannado
Registered User
Posts: 303
Joined: Mon Mar 25, 2002 6:54 pm
Location: Drenthe, The Netherlands
Contact:

Post by Shannado »

I dont have the problem with the index page, but did had the problem with the memberlist.

Next code will correct the problem with 'last visit' in the memberlist

find:

Code: Select all

$template->assign_block_vars('memberrow', array(
ROW_NUMBER' => $i + ( $HTTP_GET_VARS['start'] + 1 ),
add before:

Code: Select all

$user_timezone = ( $userdata['user_timezone'] > 12 ) ? $userdata['user_timezone'] - 50 : $userdata['user_timezone']; // DST MOD 
find:

Code: Select all

'LAST_LOGON' => ($userdata['user_level'] == ADMIN || (!$board_config['hidde_last_logon'] && $row['user_allow_viewonline'])) ? (($row['user_lastlogon'])? create_date($userdata['user_dateformat'], $row['user_lastlogon'], $userdata['user_timezone']):$lang['Never_last_logon']):$lang['Hidde_last_logon'],
replace with:

Code: Select all

'LAST_LOGON' => ($userdata['user_level'] == ADMIN || (!$board_config['hidde_last_logon'] && $row['user_allow_viewonline'])) ? (($row['user_lastlogon'])? create_date($userdata['user_dateformat'], $row['user_lastlogon'], $user_timezone):$lang['Never_last_logon']):$lang['Hidde_last_logon'],
blulegend
Registered User
Posts: 83
Joined: Wed Jan 30, 2002 5:41 pm

Post by blulegend »

That means the lastvisit mod is using the visit time of the actual user's timezone instead of the viewer's timezone. That would seem incorrect to me (the last visit mod). It should show the viewer the last visit time in the actualy timezone of the viewer.

Code: Select all

$timezone['timezone-id']['name'] = "xxx"; 
$timezone['timezone-id']['short_name'] = "xxx"; 
$timezone['timezone-id']['raw_offset'] = "xx';   // raw offset from GMT/UTC 
$timezone['timezone-id']['dst_savings'] = "xx";  // adjustment amount (precision?) 
$timezone['timezone-id']['start_month'] = "xx"; 
$timezone['timezone-id']['start_day'] = "xx"; 
$timezone['timezone-id']['start_day_of_week'] = "xx";  // used for "First Sunday of" logic 
$timezone['timezone-id']['start_hour'] = "xx"; 
$timezone['timezone-id']['start_mode'] = "xx"; // indicates using exact day, day of week, or ??? 
$timezone['timezone-id']['end_month'] = "xx"; 
$timezone['timezone-id']['end_day'] = "xx"; 
$timezone['timezone-id']['end_hour'] = "xx"; 
$timezone['timezone-id']['end_day_of_week'] = ""; 
$timezone['timezone-id']['end_mode'] = "xx"; 
I am reluctant to do this since it would require MUCH more code to be included with every page load. But maybe we can work together on simplifying it.
Narf_
Registered User
Posts: 68
Joined: Sun Mar 17, 2002 6:09 pm
Location: Netherlands
Contact:

Post by Narf_ »

Sven Ansem wrote: I dont have the problem with the index page, but did had the problem with the memberlist.

Next code will correct the problem with 'last visit' in the memberlist


Thanx that fixed the memberlist for me :-D

But how do I fix the 'Members who visited the board today' part on the index ?
Narf_
Registered User
Posts: 68
Joined: Sun Mar 17, 2002 6:09 pm
Location: Netherlands
Contact:

Post by Narf_ »

I fixed also the parts on the index:

In page_header.php:

add:

Code: Select all

$user_timezone = ( $userdata['user_timezone'] > 12 ) ? $userdata['user_timezone'] - 50 : $userdata['user_timezone']; // DST MOD 
find (several):

Code: Select all

$userdata['user_timezone']
replace with:

Code: Select all

$user_timezone
Locked

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