The following PHP Code:
function serverTimeZone_offset($userTimeZone)
{
$userDateTimeZone = new DateTimeZone($userTimeZone);
$userDateTime = new DateTime("now", $userDateTimeZone);
$serverTimeZone = date_default_timezone_get();
$serverDateTimeZone = new DateTimeZone($serverTimeZone);
$serverDateTime = new DateTime("now", $serverDateTimeZone);
return $serverDateTimeZone->getOffset($userDateTime);
}
function getDefineTimeZone($timezone)
{
$userDateTimeZone = new DateTimeZone($timezone);
return new DateTime("now", $userDateTimeZone);
}
function getServerTimeZone()
{
$serverTimeZone = date_default_timezone_get();
$serverDateTimeZone = new DateTimeZone($serverTimeZone);
return new DateTime("now", $serverDateTimeZone);
}
$userDateTime = getDefineTimeZone('America/Curacao');
$serverDateTime = getServerTimeZone();
$timeOffset = serverTimeZone_offset('America/Curacao');
var_dump($userDateTime);
var_dump($serverDateTime);
var_dump($timeOffset); // the seconds is incorrect ?!?!
// adding the timezone difference
$userDateTime->add(new DateInterval('PT'.$timeOffset.'S'));
var_dump($userDateTime);
Will output:
object(DateTime)[2]
public 'date' => string '2014-10-22 17:36:39' (length=19)
public 'timezone_type' => int 3
public 'timezone' => string 'America/Curacao' (length=15)
object(DateTime)[3]
public 'date' => string '2014-10-22 23:36:39' (length=19)
public 'timezone_type' => int 3
public 'timezone' => string 'Europe/Paris' (length=12)
int 7200
object(DateTime)[2]
public 'date' => string '2014-10-22 19:36:39' (length=19)
public 'timezone_type' => int 3
public 'timezone' => string 'America/Curacao' (length=15)
Which is obviously incorrect. The offset is returning back 7200 seconds (only 2 hours) rather than 21600 seconds (6 hours). Why?