I'm wondering if this is a bug, or if I missed something.
While creating a method to isolate the timestamp when DST switches from on to off and vice versa, I noticed a potential bug with DateTime::format('I'). When DST ends and the time is switched backwards one hour, DateTime::format('I') reports the switch one hour too late.
In the 'America/Montreal' timezone, we can look at these timestamps when DST ends:
1414904400, Sun, 02 Nov 2014 01:00:00 -0400 (DST on)
1414908000, Sun, 02 Nov 2014 01:00:00 -0500 (DST off)
1414911600, Sun, 02 Nov 2014 02:00:00 -0500 (DST off)
Notice the DST ends on the second timestamp when 01:00:00 is repeated.
But, using DateTime::format('I') the ending is reported on the third timestamp.
$timezone = new DateTimezone('America/Montreal');
$datetime = new DateTime('now', $timezone);
$datetime->setTimestamp(1414904400);
echo $datetime->format('I');
$datetime->setTimestamp(1414908000);
echo $datetime->format('I');
$datetime->setTimestamp(1414911600);
echo $datetime->format('I');
returns 110 (should be 100)
If we use date('I') we get the correct answer.
date_default_timezone_set('America/Montreal');
echo date('I', 1414904400);
echo date('I', 1414908000);
echo date('I', 1414911600);
returns 100 (as expected)
When DST begins DateTime::format('I') works fine, it only seems to fail when DST ends.
Also, I have tested this for a few different years in a few different timezones, but I have no idea of the depth of this potential bug. Much more testing is needed.
Anyone know what this is?