1--TEST-- 2RFC: DateTime and Daylight Saving Time Transitions (zone type 3, bd2) 3--CREDITS-- 4Daniel Convissor <danielc@php.net> 5--FILE-- 6<?php 7 8date_default_timezone_set('America/New_York'); 9$date_format = 'Y-m-d H:i:s T e'; 10$interval_format = 'P%dDT%hH'; 11 12/* 13 * For backward transitions, must create objects with zone type 2 14 * where specifying Daylight or Standard time is required 15 * then converting them to zone type 3. 16 */ 17 18$tz = new DateTimeZone('America/New_York'); 19 20/* 21 * Backward Transitions, diff(). 22 */ 23 24$end = new DateTime('2010-11-07 01:00:00 EST'); 25$end->setTimeZone($tz); 26$start = new DateTime('2010-11-07 01:59:59'); 27echo 'bd0 ' . $end->format($date_format) . ' - ' . $start->format($date_format) 28 . ' = ' . $start->diff($end)->format('P%dDT%hH%iM%sS') . "\n"; 29 30$end = new DateTime('2010-11-07 01:30:00 EST'); 31$end->setTimeZone($tz); 32$start = new DateTime('2010-11-06 04:30:00'); 33echo 'bd5 ' . $end->format($date_format) . ' - ' . $start->format($date_format) 34 . ' = ' . $start->diff($end)->format($interval_format) . "\n"; 35 36$end = new DateTime('2010-11-07 01:30:00 EDT'); 37$end->setTimeZone($tz); 38$start = new DateTime('2010-11-06 04:30:00'); 39echo 'bd6 ' . $end->format($date_format) . ' - ' . $start->format($date_format) 40 . ' = ' . $start->diff($end)->format($interval_format) . "\n"; 41 42$end = new DateTime('2010-11-07 01:00:00 EST'); 43$end->setTimeZone($tz); 44$start = new DateTime('2010-11-06 01:00:00'); 45echo 'bd8a ' . $end->format($date_format) . ' - ' . $start->format($date_format) 46 . ' = ' . $start->diff($end)->format($interval_format) . "\n"; 47 48$end = new DateTime('2010-11-07 01:00:00 EDT'); 49$end->setTimeZone($tz); 50$start = new DateTime('2010-11-06 01:00:00'); 51echo 'bd8b ' . $end->format($date_format) . ' - ' . $start->format($date_format) 52 . ' = ' . $start->diff($end)->format($interval_format) . "\n"; 53 54echo "\n"; 55?> 56--EXPECT-- 57bd0 2010-11-07 01:00:00 EST America/New_York - 2010-11-07 01:59:59 EDT America/New_York = P0DT0H0M1S 58bd5 2010-11-07 01:30:00 EST America/New_York - 2010-11-06 04:30:00 EDT America/New_York = P0DT22H 59bd6 2010-11-07 01:30:00 EDT America/New_York - 2010-11-06 04:30:00 EDT America/New_York = P0DT21H 60bd8a 2010-11-07 01:00:00 EST America/New_York - 2010-11-06 01:00:00 EDT America/New_York = P1DT0H 61bd8b 2010-11-07 01:00:00 EDT America/New_York - 2010-11-06 01:00:00 EDT America/New_York = P0DT24H 62