public static function toTimezone($Timestamp)
{
static $GuestHourOffset;
$Now = time();
// Alter the timestamp based on the user's hour offset
$Session = Gdn::session();
$HourOffset = 0;
if ($Session->UserID > 0) {
$HourOffset = $Session->User->HourOffset;
} elseif (class_exists('DateTimeZone')) {
if (!isset($GuestHourOffset)) {
$GuestTimeZone = c('Garden.GuestTimeZone');
if ($GuestTimeZone) {
try {
$TimeZone = new DateTimeZone($GuestTimeZone);
$Offset = $TimeZone->getOffset(new DateTime('now', new DateTimeZone('UTC')));
$GuestHourOffset = floor($Offset / 3600);
} catch (Exception $Ex) {
$GuestHourOffset = 0;
logException($Ex);
}
}
}
$HourOffset = $GuestHourOffset;
}
if ($HourOffset != 0) {
$SecondsOffset = $HourOffset * 3600;
$Timestamp += $SecondsOffset;
$Now += $SecondsOffset;
}
return $Timestamp;
}