Forums | Mahara Themes

General discussion /
changing server time stamp for posts to your local time


anonymous profile picture
Account deleted
Posts: 47

18 March 2009, 18:00

Hi. This is just a rather brute force and crude start, but here is something that I am using to change what time is shown for forum posts.  My server is in Texas (US Central timezone) and I am in Florida (Eastern Time Zone). 

 I eventually want to make it so we read either the local time from vistor's PC (using jquery or something) and compute the difference, but this atleast clears up my own difficulty with my 1 hour offset from my server.

 {php}
// place this code in the /interaction/forum/theme/default/simplepost.tpl file in place of the
// line <div class="posttime">{$post->ctime}</div>
//
// following simply takes the stored datetime stamp of a post and displays a datetime shifted by certain offset
// in case your server is in Japan and your organization is in Kansas
// Note this does not adjust for the vistors timezone, although could be adapted if we stored the server
// timezone in the config file and the members in their profile record, with a default timezone display for non members
//
// Following variables are hardcoded here, but eventually should be consolidated and put in config file or site setup
$timezonestring = "EST"; // just to give visitor feedback on what timezone they are seeing in each post after hourshift applied
$hourshift = -1; // number of hours + or - shifted from server timezone
//
$thepost = $this->get_template_vars('post'); // get the smarty variable $post
$theposttimedate = $thepost->ctime; // extract the datetime part of the smarty variable
$timedatestamp = strtotime($theposttimedate); // create a valid php datetime variable
// echo "<BR>".date("Y-m-d H:i:s",$timedatestamp); // debug of datetime stamp
echo "<div class='posttime'>".date("D, M j Y, g:i a",$timedatestamp + ($hourshift*3600))." ".$timezonestring."</div>"; // the shifted time to your zone, not the servers zone
{/php}

Tested the above with 1.1.2,

Peace,

Jamie

 

anonymous profile picture
Account deleted
Posts: 47

19 March 2009, 8:52

In addition to the above, make the following change in the /interaction/forum/theme/default/topics.tpl file to have it display the last post time in your shifted timezone also, in almost the same way as the above does for the post itself:

 

{php}
// place this code in the /interaction/forum/theme/default/topics.tpl file in place of the
// TEXT (not a whole line) {$topic->lastposttime}
//
// following simply takes the stored datetime stamp of a last post and displays a datetime shifted by certain offset
// in case your server is in Japan and your organization is in Kansas
// Note this does not adjust for the vistors timezone, although could be adapted if we stored the server
// timezone in the config file and the members in their profile record, with a default timezone display for non members
//
// Following variables are hardcoded here, but eventually should be consolidated and put in config file or site setup
$timezonestring = "EST"; // just to give visitor feedback on what timezone they are seeing in each post after hourshift applied
$hourshift = 1; // number of hours + or - shifted from server timezone
//
$thetopic = $this->get_template_vars('topic'); // get the smarty variable $topic
$thetopictimedate = $thetopic->lastposttime; // extract the datetime part of the smarty variable
$timedatestamp = strtotime($thetopictimedate); // create a valid php datetime variable
// echo "<BR>".date("Y-m-d H:i:s",$timedatestamp); // debug of datetime stamp
echo date("D, M j Y, g:i a",$timedatestamp + ($hourshift*3600))." ".$timezonestring; // the shifted time to your zone, not the servers zone
{/php}

 

Once again, this is more of a patch for display purposes, and code to change the timezones used for individual users preference would be better. 

Also, although the logic (php code in this example) is generally prefered to be kept out of the templates (smarty), in this case I think it makes sense, since we are just transforming a display value. 

Final note: If you make changes like this, remember to keep a change log, so that when you upgrade you can make the same changes again in the new files. The updated files will erase your changes.

Good luck,

Jamie

 

anonymous profile picture
Account deleted
Posts: 1643

19 March 2009, 18:38

Hi - the best way to keep a track of your changes is by using git and tracking our 1.1_STABLE branch, with a new branch for your changes. But failing that, you will find that running git locally, or even preparing patches with 'diff' (unix tool), will help with this. Smile
3 results