doudandui1592 2014-01-21 09:46
浏览 79

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!

  • 写回答

2条回答 默认 最新

  • doulu1945 2014-01-21 09:56
    关注

    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);
    
    评论

报告相同问题?

悬赏问题

  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码