PHP模拟夏令时

I have some code that handles dates and times. I think it's OK, but want to test that it works when the clocks go forwards for DST.

I can change the timezone using date_default_timezone_set('Europe/London');, and wondered if there is an easy to simulate being in DST without having to wait till the clocks change!

You don't provide details on what you want to test but I assume you have functions to do time-related stuff, e.g.:

function setExpiryTime(DateTime $start, $minutes){
}

The obvious test is to provide input parameters that will make your code cross DST boundaries. You can either find such information in your favourite search engine or run a simple PHP snippet:

<?php

$timezone = new DateTimeZone('Europe/London');
print_r( $timezone->getTransitions(mktime(0, 0, 0, 1, 1, date('Y')), mktime(0, 0, 0, 12, 31, date('Y'))) );
Array
(
    [0] => Array
        (
            [ts] => 1388530800
            [time] => 2013-12-31T23:00:00+0000
            [offset] => 0
            [isdst] => 
            [abbr] => GMT
        )

    [1] => Array
        (
            [ts] => 1396141200
            [time] => 2014-03-30T01:00:00+0000
            [offset] => 3600
            [isdst] => 1
            [abbr] => BST
        )

    [2] => Array
        (
            [ts] => 1414285200
            [time] => 2014-10-26T01:00:00+0000
            [offset] => 0
            [isdst] => 
            [abbr] => GMT
        )

)

Thus you can test:

setExpiryTime(new DateTime('2014-03-30T00:55:00+0000'), 10);
setExpiryTime(new DateTime('2014-10-26T00:55:00+0000'), 10);

you can certainly find out, whether user is in Daylight saving zone or daylight saving is currently in effect.

echo date('I', time());

This returns 0/1; where,

0 = Daylight saving is not in effect. 1 = Daylight saving is in effect.

more details : http://php.net/manual/en/function.date.php

Based on this result you can make conditional code to simulate your output.