My server time is in GMT, and I do the following whenever someone comes online.
// Set a default timezone
$defaultTimeZone = 'America/Toronto';
// load the user, if they are online...
$onlineUser = new user();
if (isset($_SESSION['user_id']))
{
if ($onlineUser->loadUser($_SESSION['user_id']))
{
$defaultTimeZone = $onlineUser->timeZone;
}
}
// set time zones
date_default_timezone_set($defaultTimeZone);
$db->query("SET SESSION time_zone = '".$defaultTimeZone."'");
So, my problem is this... whenever someone does something it stores the date/time in the users local time... causing me a whole wack of issues.
All I want is for everything to be stored in GMT, but have the users see & interact with the data in their local time zone.
EDIT:
Here is how I am updating the users status:
public function updateStatus()
{
global $db, $common, $config;
// update the user record
$data = array(
'date_last_active' => new Zend_Db_Expr('NOW()')
);
$db->update('users', $data, 'user_id='.$this->userId);
}
Here is my function to turn a date stamp into seconds...
public function dateTimeToUnixTime($dateString)
{
if (strlen($dateString) < 10)
{
return "";
}
$parseDateTime = split(" ", $dateString);
$parseDate = split("-", $parseDateTime[0]);
if (isset($parseDateTime[1]))
{
$parseTime = split(":", $parseDateTime[1]);
}
else
{
$parseTime = split(":", "00:00:00");
}
return mktime($parseTime[0], $parseTime[1], $parseTime[2], $parseDate[1], $parseDate[2], $parseDate[0]);
}
And finally, how I am comparing the dates:
$date = $oUser->dateLastActive;
$lastSeen = abs($common->dateTimeToUnixTime(date('Y-m-d H:i:s')) - $common->dateTimeToUnixTime($date));
if ($lastSeen < 300 )
{
echo "<font size='1' color='green'><strong>Online</strong></font>";
}
if ($lastSeen >= 300)
{
echo "<font size='1' color='black'><strong>Offline</strong></font>";
}