Beginning to learn about the php dateTime & dateTimezone objects. Assuming a server in US/Eastern and creating a time in another timezone, the goal is to convert and store the time (ie London) on the server (US/Eastern), in server time. Using this code:
$runTime = '2013-04-10 07:45:00';
$serverTimezone = new DateTimeZone ( 'US/Eastern');
$checkinTimezone = new DateTimeZone ( 'Europe/London');
$checkinTime = new DateTime ( $runTime, $serverTimezone );
$offset = $serverTimezone -> getOffset ( $checkinTime );
echo "<br/><pre>";
echo 'London: ' . date ( 'Y-m-d H:i', $checkinTime -> format ( 'U' ) ) . "<br/>";
echo "<br/>offset: " . $offset . "<br/>";
echo 'Local: ' . date ( 'Y-m-d H:i', $checkinTime -> format ( 'U' ) + $offset );
-14400 is always returned, wether before or after today (Europe switched to DST earlier today). In an aha moment, I discovered the documentation for getOffset says Returns the timezone offset from GMT
.
Is there a simple way to convert that time to US/Eastern? Do I have to go into the getTransitions, find the day DST begins and do the calculation manually? This only matters on the first day of each spring/fall switch.