View Full Version : Chat Modifications - Fix vbShout Timezone problem
newhere
04-09-2007, 10:00 PM
This vbShout plugin: http://www.vbhackers.com/f76/ajax-flatfile-vbshout-2-1-a-4536/
Has a serious bug with Time Zone changing to that of the last person to post in the shout box.
Here is a fix so that each user will see the time in their local timezone correctly.
1. Open template forumhome_vbshout_shout
Find this (should be at the very beginning):
<tr>
After it add:
<td nowrap align="left" valign="top">
<font size="1">
<date>{$Shout['time']}</date>
</font>
</td>
Make sure that the "date" and "/date" tags are on the same line, and with no spaces between them and the $Shout variable, just as above. These are not valid html tags, and we are going to write code to replace them ourselves.
2. Open template forumhome_vbshout
Find:
Shouts.innerHTML = '<table cellpadding="1" cellspacing="3" border="0" width="95%" align="left">' + ShoutRequest.handler.responseText + '</table>'
Replace it with:
var formatMe = ShoutRequest.handler.responseText
formatMe = replaceDates(formatMe);
Shouts.innerHTML = '<table cellpadding="1" cellspacing="0" border="0" width="100%" align="left">' + formatMe + '</table>'
In the same template
Find this:
function sb_CollectHV(sbForm)
Before it add:
// replaces <date> tags
function replaceDates(s) {
var ret = "";
var matches = s.match(/<date>\d+<\/date>/g);
for(var i = 0; matches != null && i < matches.length; i++) {
var utc = matches[i].match(/\d+/);
var date = new Date(utc * 1000);
ret = ret + s.substr(0, s.indexOf(matches[i]));
ret = ret + (date.getMonth()+1) + "/" +
date.getDate() + "/" +
date.getFullYear() + " " +
date.getHours() + ":" +
((date.getMinutes() < 10) ? "0" : "") +
date.getMinutes() + ":" +
((date.getSeconds() < 10) ? "0" : "") +
date.getSeconds() + " ";
s = s.substr(s.indexOf(matches[i]) + matches[i].length);
}
ret = ret + s;
return ret;
}
3. Open file vbshout.php
FInd this (There are similar code blocks, this should be in the function rewrite_shoutbox_flatfile() around line 226):
$Shout['time'] = buildTime($Shout['s_time']);
$Shout['s_shout'] = bbcodeparser($Shout['s_shout']);
$Shout['style'] = '';
$Shout['data'] = unserialize($Shout['s_data']);
$Shout['username'] = fetch_musername($Shout, 'usergroupid');
if (preg_match("#(\#)?0099FF#i", $Shout['data']['color']) && $Shout['s_by'] != 1)
{
$Shout['data']['color'] = '';
}
Replace it with:
// $Shout['time'] = buildTime($Shout['s_time']);
$Shout['time'] = $Shout['s_time'];
$Shout['s_shout'] = bbcodeparser($Shout['s_shout']);
$Shout['style'] = '';
$Shout['data'] = unserialize($Shout['s_data']);
$Shout['username'] = fetch_musername($Shout, 'usergroupid');
if (preg_match("#(\#)?0099FF#i", $Shout['data']['color']) && $Shout['s_by'] != 1)
{
$Shout['data']['color'] = '';
}
This should now pass the date as UTC and JavaScript will convert it on the client side to the appropriate date.
Tulsa
04-10-2007, 02:25 AM
Gave it a whirl and checked the edits twice. It's only showing "Loading"...
lovelypk
04-10-2007, 02:25 AM
i was looking for this.
thank's.
dbirosel
04-10-2007, 02:29 AM
Works great... can we have 12 hour time instead? How about the date being more simple like instead of 4/9/2007 have it as 4/9? How about adding brackets to the timestamps?
Overall, it's running great on my site. Thanks!
dbirosel
04-10-2007, 02:30 AM
Gave it a whirl and checked the edits twice. It's only showing "Loading"...
Happened to me also, but i just posted a test message, and then all of a sudden it showed the current conversation. So far it's working good, just looks kinda ugly. lol :P
lovelypk
04-10-2007, 02:32 AM
i am getting random number's instead of date, like this "1176175903".
dbirosel
04-10-2007, 02:37 AM
i am getting random number's instead of date, like this "1176175903".
Are you using the flat file version from vbhackers? Is this your first time editing the vbshout.php and vbshout templates?
newhere
04-10-2007, 02:37 AM
i am getting random number's instead of date, like this "1176175903".
Did you modify all the templates correctly?
newhere
04-10-2007, 02:40 AM
Works great... can we have 12 hour time instead? How about the date being more simple like instead of 4/9/2007 have it as 4/9? How about adding brackets to the timestamps?
Overall, it's running great on my site. Thanks!
For formatting, you can change the function:
"replaceDates(s)"
Here:
ret = ret + (date.getMonth()+1) + "/" +
date.getDate() + "/" +
date.getFullYear() + " " +
date.getHours() + ":" +
((date.getMinutes() < 10) ? "0" : "") +
date.getMinutes() + ":" +
((date.getSeconds() < 10) ? "0" : "") +
date.getSeconds() + " ";
To whatever you like.
dbirosel
04-10-2007, 02:44 AM
For formatting, you can change the function:
"replaceDates(s)"
Here:
ret = ret + (date.getMonth()+1) + "/" +
date.getDate() + "/" +
date.getFullYear() + " " +
date.getHours() + ":" +
((date.getMinutes() < 10) ? "0" : "") +
date.getMinutes() + ":" +
((date.getSeconds() < 10) ? "0" : "") +
date.getSeconds() + " ";
To whatever you like.
Does this code also change from 24 hour to 12 hour time?
lovelypk
04-10-2007, 02:44 AM
Did you modify all the templates correctly?
working now.
12 hour clock timing will be much better though.
newhere
04-10-2007, 02:45 AM
just looks kinda ugly. lol :P
Sorry, I have a lot of custom code on my install.
In that initial template edit, try setting font size="2" instead of size="1", or change the td attributes to otherwise match what your tables look like.
<td nowrap align="left" valign="top">
<font size="1">
<date>{$Shout['time']}</date>
</font>
</td>
dbirosel
04-10-2007, 02:48 AM
Thanks newhere! Loving the support so far!
newhere
04-10-2007, 02:54 AM
Thanks newhere! Loving the support so far!
It's kind of an ugly hack around this static html nonsense. But it works. It was not acceptable to me to have no timestamp on shouts, and it was also not acceptable to have timezone constantly changing to whatever timezone of the last user posting a shout.
Tulsa
04-10-2007, 02:58 AM
Thanks for this...
If anyone had the time showing before and now you've got a bunch of numbers after the date/time and before the name in the forumhome_vbshout_shout, you probably added this line to it
{$Shout['time']}
remove it to remove those numbers.
Now how to get rid of the date and just have the time...
dbirosel
04-10-2007, 02:59 AM
Didn't see you answer this yet, but is it possible to change it from 24 hour to 12 hour instead? :D
newhere
04-10-2007, 03:01 AM
Now how to get rid of the date and just have the time...
You can format the date however you want if you know a bit of javascript:
From my post above
https://vborg.vbsupport.ru/showpost.php?p=1223786&postcount=10
Tulsa
04-10-2007, 03:06 AM
You can format the date however you want if you know a bit of javascript:
From my post above
https://vborg.vbsupport.ru/showpost.php?p=1223786&postcount=10
(IF) would be the key word in that line..
I can delete with the best of the them however.. :D
the date is gone.
newhere
04-10-2007, 03:16 AM
Didn't see you answer this yet, but is it possible to change it from 24 hour to 12 hour instead? :D
for 12 hour time with brackets:
replace
ret = ret + (date.getMonth()+1) + "/" +
date.getDate() + "/" +
date.getFullYear() + " " +
date.getHours() + ":" +
((date.getMinutes() < 10) ? "0" : "") +
date.getMinutes() + ":" +
((date.getSeconds() < 10) ? "0" : "") +
date.getSeconds() + " ";
with
var append = "AM";
var hour = date.getHours();
if(hour > 12) {
hour = hour - 12;
append = "PM";
}
if(hour == 0) {
hour = 12;
append = "AM";
}
ret = ret + "[" + (date.getMonth()+1) + "/" +
date.getDate() + "/" +
date.getFullYear() + " " +
hour + ":" +
((date.getMinutes() < 10) ? "0" : "") +
date.getMinutes() + " " +
((date.getSeconds() < 10) ? "0" : "") +
date.getSeconds() + " " + append + "]";
dbirosel
04-10-2007, 03:19 AM
Omg perfect!!!! Thanks alot!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!
newhere
04-10-2007, 03:20 AM
Now how to get rid of the date and just have the time...
to get rid of the date and just have the time:
ret = ret + "[" + date.getHours() + ":" +
((date.getMinutes() < 10) ? "0" : "") +
date.getMinutes() + " " +
((date.getSeconds() < 10) ? "0" : "") +
date.getSeconds() + "]";
newhere
04-10-2007, 03:37 AM
Omg perfect!!!! Thanks alot!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!
This isn't fully tested.
There might be a bug in this.
before
if(hour > 12) {
you might want to add something like:
if(hour == 12) {
append = "PM";
}
Otherwise 12 noon might show up as AM
dbirosel
04-10-2007, 03:41 AM
So is this how it suppose to look?
var append = "AM";
var hour = date.getHours();
if(hour == 12) {
append = "PM";
}
if(hour > 12) {
hour = hour - 12;
append = "PM";
}
if(hour == 0) {
hour = 12;
append = "AM";
}
ret = ret + "[" +
hour + ":" +
((date.getMinutes() < 10) ? "0" : "") +
date.getMinutes() + ":" +
((date.getSeconds() < 10) ? "0" : "") +
date.getSeconds() + " " + append + "]";
newhere
04-10-2007, 03:45 AM
So is this how it suppose to look?
var append = "AM";
var hour = date.getHours();
if(hour == 12) {
append = "PM";
}
if(hour > 12) {
hour = hour - 12;
append = "PM";
}
if(hour == 0) {
hour = 12;
append = "AM";
}
ret = ret + "[" +
hour + ":" +
((date.getMinutes() < 10) ? "0" : "") +
date.getMinutes() + ":" +
((date.getSeconds() < 10) ? "0" : "") +
date.getSeconds() + " " + append + "]";
Sure I think that'll work.
Tulsa
04-10-2007, 03:58 AM
I didn't much care for the date and the seconds. I got rid of the bracket and put a simple dash between the time and the username.
var append = "AM";
var hour = date.getHours();
if(hour > 12) {
hour = hour - 12;
append = "PM";
}
if(hour == 0) {
hour = 12;
append = "AM";
}
ret = ret + hour + ":" +
((date.getMinutes() < 10) ? "0" : "") +
date.getMinutes() + " " + append + " - ";
The shoutbox is finally fixed.. Thanks again newhere. :up:
newhere
04-10-2007, 04:03 AM
I didn't much care for the date and the seconds. I got rid of the bracket and put a simple dash between the time and the username.
Cool, whatever works for you. Thanks for posting your variation. I hope others do the same. :)
dbirosel
04-10-2007, 05:57 AM
Here's a bug...
When pruning (/prune) it doesn't ajax the original message when pruning. So we would need to refresh the page. So instead it would say "Loading....."
newhere
04-10-2007, 06:03 AM
Here's a bug...
When pruning (/prune) it doesn't ajax the original message when pruning. So we would need to refresh the page. So instead it would say "Loading....."
I haven't seen this myself. If it's truly an AJAX bug, it may be related to the original mod. All this hack does is a small string replacement on whatever html the AJAX requests return before assigning it to the div's innerHTML.
What do you mean by "pruning"?
dbirosel
04-10-2007, 06:23 AM
I haven't seen this myself. If it's truly an AJAX bug, it may be related to the original mod. All this hack does is a small string replacement on whatever html the AJAX requests return before assigning it to the div's innerHTML.
What do you mean by "pruning"?
Well everything was operating just fine before this mod.
When people engage in conversations on the shoutbox, you can clear out all the recent messages by typing in "/prune".
newhere
04-10-2007, 06:28 AM
Well everything was operating just fine before this mod.
When people engage in conversations on the shoutbox, you can clear out all the recent messages by typing in "/prune".
Hmm, okay I didn't know about this command, I just installed the shoutbox today. I'll look into this tomorrow if I can.
Thanks for your help and feedback.
dbirosel
04-10-2007, 06:30 AM
Np, i'll be on this thread frequently, so if u need anything, ill help you provide information.
dbirosel
04-10-2007, 06:32 AM
Btw, here are the codes:
The codes are:
/*me bla bla bla->without the * the irc like command that says "nick bla bla bla"
/prune -> deletes all the shouts
/prune nick -> deletes all that nick's shouts
/prunshout bla bla -> deletes the latest shout which is the words "bla bla"
be careful: if you want to delete a shout that contains a smilie you have to type the smilie code also
newhere
04-10-2007, 06:45 AM
Btw, here are the codes:
The codes are:
/*me bla bla bla->without the * the irc like command that says "nick bla bla bla"
/prune -> deletes all the shouts
/prune nick -> deletes all that nick's shouts
/prunshout bla bla -> deletes the latest shout which is the words "bla bla"
be careful: if you want to delete a shout that contains a smilie you have to type the smilie code also
I've just tried this and /prune is still working for me. So I cannot recreate this on my server. Do you know if you have the latest version of the vbShout plugin installed? Or if this was a known issue with the vbShout plugin?
dbirosel
04-10-2007, 06:47 AM
The /prune is working, but it displays a "Loading..." text. It suppose to say that the shoutbox has been cleared.
newhere
04-10-2007, 07:06 AM
The /prune is working, but it displays a "Loading..." text. It suppose to say that the shoutbox has been cleared.
Good bug.
This:
for(var i = 0; i < matches.length; i++) {
Should be replaced with:
for(var i = 0; matches != null && i < matches.length; i++) {
Though this introduces a new bug, as I believe the "system response" date needs to be fixed so it's Timestamp has the correct timezone.
That I will try to work on tomorrow... or tonight, maybe.. hm.
I'll go edit my original post to reflect this.
ssslippy
04-10-2007, 07:20 AM
Ive installed this with a fresh version of shoutbox and it still switches the the to the currently users time zone.
Hornstar
04-10-2007, 10:29 AM
Yeah this is something that was missed big time by my members at first, but now im not sure if i want it back lol.
newhere
04-10-2007, 02:12 PM
Ive installed this with a fresh version of shoutbox and it still switches the the to the currently users time zone.
Can you try to debug this by removnig the "date" tags from:
<date>{$Shout['time']}</date>
so you have just:
{$Shout['time']}
And then see if users in different time zones receive the same UTC value? (They should)
Are your users' local clocks set correctly?
dbirosel
04-10-2007, 07:29 PM
Ive installed this with a fresh version of shoutbox and it still switches the the to the currently users time zone.
If they are using Windows, make sure they update there computers. Windows have a special patch, to correct the effect of the daylight savings.
Tulsa
04-10-2007, 09:05 PM
Here's a bug...
When pruning (/prune) it doesn't ajax the original message when pruning. So we would need to refresh the page. So instead it would say "Loading....."
Yes, I gave this one a run and it didn't appear to do anything. I just typed in a new shout and everything was cleared out just fine. So the only thing it's not doing is bringing up the old message the shoutbox had been cleared.
Tulsa
04-10-2007, 09:38 PM
Now this one had me totally baffled...
I have just a few users who are using eastern time zone, both that I know about have DST set in their profile. They are both showing an hour behind. It's not on their end as I have logged in as them and it's shows incorrectly to me as well. However I have other users with EST and they are fine. All the settings are the same.
I have people from Britan, Greece, France, Japan and of course all over the states and only these couple that I know about so far are an issue...
rjmjr69
04-11-2007, 05:40 AM
Now this one had me totally baffled...
I have just a few users who are using eastern time zone, both that I know about have DST set in their profile. They are both showing an hour behind. It's not on their end as I have logged in as them and it's shows incorrectly to me as well. However I have other users with EST and they are fine. All the settings are the same.
I have people from Britan, Greece, France, Japan and of course all over the states and only these couple that I know about so far are an issue...
Had this same problem when the DST came up. What I had to do to fix it for some members was ask them to select in the user cp/Edit Options/Date + TimeZone
Select: DST CORRECTION ALWAYS ON.
newhere
04-11-2007, 08:11 PM
Had this same problem when the DST came up. What I had to do to fix it for some members was ask them to select in the user cp/Edit Options/Date + TimeZone
Select: DST CORRECTION ALWAYS ON.
Cool. Thanks rj! I have not seen any of these problems. As I say, the conversion all happens with javascript, (everyone gets the same UTC value sent to their client) so I would guess any problems with conversion are somehow related to the users own local timezone settings or their javascript settings. I don't know how vBulletin's user cp/Edit Options/Date effects the client. Is there a cookie being set or something? That might explain things??
rjmjr69
04-11-2007, 08:17 PM
Cool. Thanks rj! I have not seen any of these problems. As I say, the conversion all happens with javascript, (everyone gets the same UTC value sent to their client) so I would guess any problems with conversion are somehow related to the users own local timezone settings or their javascript settings. I don't know how vBulletin's user cp/Edit Options/Date effects the client. Is there a cookie being set or something? That might explain things??
This problem drove me insane for three days. I contacted everyone Jelsoft my host reinstalled VB to no avail. Just messing around with some users accounts I set the DST to always and BOOM everything worked. So I have no idea to be honest. One answer I got from Jelsoft was that maybe the server was not reporting the right time.
But whatever may cause it My trick worked to fix it I would like to know the cause tho Seeing how not everyone is affected by it. One other thing I will mention is if People have not updated their windows with ms updates for the DST then they also have this issue.
Tulsa
04-11-2007, 09:41 PM
I use a MAC and Firefox so I missed seeing this till someone took a pic for me. For users of IE7 there is now a scroll bar at the bottom, just above the input line that is not showing in Firefox either PC or MAC.
Anyone else seeing this?
newhere
04-11-2007, 11:02 PM
I use a MAC and Firefox so I missed seeing this till someone took a pic for me. For users of IE7 there is now a scroll bar at the bottom, just above the input line that is not showing in Firefox either PC or MAC.
Anyone else seeing this?
This might be due to the additional td tags.
You could try removing the td tags from the first step in the mod and instead place the
<date>...</date>
tags just before the username.
ssslippy
04-12-2007, 07:06 PM
I believe the issue is with this code
var formatMe = ShoutRequest.handler.responseText
formatMe = replaceDates(formatMe);
Shouts.innerHTML = '<table cellpadding="1" cellspacing="0" border="0" width="100%" align="left">' + formatMe + '</table>'
It should be
var formatMe = ShoutRequest.handler.responseText
formatMe = replaceDates(formatMe);
Shouts.innerHTML = '<table cellpadding="1" cellspacing="0" border="0" width="95%" align="left">' + formatMe + '</table>'
Might want to make this change to the actuall mod itself, this causes a hscroll bar and its quite annoying.
newhere
04-12-2007, 08:25 PM
I believe the issue is with this code
var formatMe = ShoutRequest.handler.responseText
formatMe = replaceDates(formatMe);
Shouts.innerHTML = '<table cellpadding="1" cellspacing="0" border="0" width="100%" align="left">' + formatMe + '</table>'
It should be
var formatMe = ShoutRequest.handler.responseText
formatMe = replaceDates(formatMe);
Shouts.innerHTML = '<table cellpadding="1" cellspacing="0" border="0" width="95%" align="left">' + formatMe + '</table>'
Might want to make this change to the actuall mod itself, this causes a hscroll bar and its quite annoying.
Either way (with your code or with mine), I get a horizontal scroll bar when someone posts a shout which is too long.
Terminatoronly
04-28-2007, 07:59 PM
when i installed it i didnt get any time with the shout how can i add the time ???
parabat
05-02-2007, 03:29 PM
Great hack, so thanx. works a treat :up:
-PB
parabat
05-03-2007, 09:08 AM
Either way (with your code or with mine), I get a horizontal scroll bar when someone posts a shout which is too long.
Just as a side.. the scrollbar appears in IE6 & IE7 (without a long posting), but not in Firefox.
-PB
jessej
06-01-2007, 06:13 AM
when i installed it i didnt get any time with the shout how can i add the time ???
same here.
i hope someone will answer cause i had it on v2.0, and i really want it on v2.1. :)
thanks- and this is a GREAT hack.
i canĀ“t change somebody help me
oz_moses
06-04-2008, 12:14 AM
Cheers for the mods, much appreciated
CMGU, perhaps if you ask a question you might find help more forthcoming.
oz_moses
06-04-2008, 12:38 AM
Ok, here's my customisations for anyone who's interested. These changes to the replaceDates function do the following
Droped the seconds - the shouts are displayed in order anyway, my users don't care if a shout was 3 or 49 seconds ago
Changed the date format to dd-mon , easier to read, all months are 3 letters helps keep it aligned at the month turnover.
// replaces <date> tags
function replaceDates(s) {
var ret = "";
var matches = s.match(/<date>\d+<\/date>/g);
var months=['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug', 'Sep','Oct','Nov','Dec'];
for(var i = 0; matches != null && i < matches.length; i++) {
var utc = matches[i].match(/\d+/);
var date = new Date(utc * 1000);
ret = ret + s.substr(0, s.indexOf(matches[i]));
ret = ret + (
date.getDate() + "-" +
months[date.getMonth()]) + " " +
((date.getHours() < 10) ? " " : "") +
date.getHours() + ":" +
((date.getMinutes() < 10) ? "0" : "") +
date.getMinutes() + " ";
s = s.substr(s.indexOf(matches[i]) + matches[i].length);
}
ret = ret + s;
return ret;
}
oz_moses
06-04-2008, 12:41 AM
same here.
i hope someone will answer cause i had it on v2.0, and i really want it on v2.1. :)
thanks- and this is a GREAT hack.
I found that changes aren't rendered until you make a new shout... so just shout!
oz_moses
06-04-2008, 12:46 AM
Just as a side.. the scrollbar appears in IE6 & IE7 (without a long posting), but not in Firefox.
-PB
I noticed the horizontal scroll initially in IE6, it was on all the time.
I made an edit in forumhome_vbshout template to chang the table width to 95% as per the original hack which seems to have fixed it.
Shouts.innerHTML = '<table cellpadding="1" cellspacing="0" border="0" width="95%" align="left">' + formatMe + '</table>'
seems to be working in IE6 and IE7. Haven't tested Firefox yet...
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.