I need to work out the difference in hours between two timezones and I am running into some issues when the timezone that is ahead moves to the next day.
Example:
//Let's say it is 11pm 23:00 in LA
$local_tz = new DateTimeZone('America/Los_Angeles');
$local = new DateTime('now', $local_tz);
$local_hour = $local->format('H');
//NY is 3 hours ahead, so it is 2am, 02:00
$user_tz = new DateTimeZone('America/New_York');
$user = new DateTime('now', $user_tz);
$user_hour = $user->format('H');
Following the example in this question (Calculate hours between dates in different time zones) I get an incorrect result:
$diff = $user_tz->getOffset($local);
error_log('$diff '.gmdate("H:i:s", $diff)); //outputs 20:00:00
If it was 4pm in LA, therefore 7pm in NY then it is easy:
$time_diff = ($user_h - $local_h); //$time_diff = 3;
But when NY moves to the next day I again get incorrect results:
$time_diff = ($user_h - $local_h); //$time_diff = -21;
So how can I account for another timezone which has moved to a new day?