Cip
09-28-2008, 07:05 AM
I have several custom pages in vBulletin currently presenting dates from timestamps by using the date() function in PHP. But this is very inconvenient for some of my users as I'm currently only displaying the dates and times according to my own timezone.
I tried to come up with a solution but it proved to be rather flawed..
Here's what I did:
$timestamp = $character->getAttr('lastlogout');
//If the timezoneoffset field in vb_user table contains a -
if (ereg("^\-)$",$vbulletin->userinfo['timezoneoffset'])){
//Besides from substracting the timezoneoffset we also substract 1 hour because I'm GMT+1
$timezoneoffset = date("G", $timestamp).$vbulletin->userinfo['timezoneoffset']-1;
}else{
//No -, lets sum it instead, but still remove 1 hour because I'm GMT+1
$timezoneoffset = date("G", $timestamp)+$vbulletin->userinfo['timezoneoffset']-1;
}
//Generate date string from a timestamp with the appropriate changes to the timezone
$lastlogin = date("M j, G:i Y", mktime($timezoneoffset, date("i", $timestamp), 0, date("m", $timestamp), date("d", $timestamp), date("Y", $timestamp)));
Now here's the catch. I haven't found a way to see wether a member has DST turned on, so the Last Login field has a tendency to jump ahead (or maybe it was backwards :o) an hour.
Is there an easier way to do this? Or at least to find out the DST settings?
I tried to come up with a solution but it proved to be rather flawed..
Here's what I did:
$timestamp = $character->getAttr('lastlogout');
//If the timezoneoffset field in vb_user table contains a -
if (ereg("^\-)$",$vbulletin->userinfo['timezoneoffset'])){
//Besides from substracting the timezoneoffset we also substract 1 hour because I'm GMT+1
$timezoneoffset = date("G", $timestamp).$vbulletin->userinfo['timezoneoffset']-1;
}else{
//No -, lets sum it instead, but still remove 1 hour because I'm GMT+1
$timezoneoffset = date("G", $timestamp)+$vbulletin->userinfo['timezoneoffset']-1;
}
//Generate date string from a timestamp with the appropriate changes to the timezone
$lastlogin = date("M j, G:i Y", mktime($timezoneoffset, date("i", $timestamp), 0, date("m", $timestamp), date("d", $timestamp), date("Y", $timestamp)));
Now here's the catch. I haven't found a way to see wether a member has DST turned on, so the Last Login field has a tendency to jump ahead (or maybe it was backwards :o) an hour.
Is there an easier way to do this? Or at least to find out the DST settings?