1--TEST-- 2RFC: DateTime and Daylight Saving Time Transitions (zone type 1) 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 e'; 10$interval_format = 'P%dDT%hH'; 11 12/* 13 * Forward Transitions, diff(). 14 */ 15$end = new DateTime('2010-03-14 03:00:00 -0400'); 16$start = new DateTime('2010-03-14 01:59:59 -0500'); 17echo 'fd1 ' . $end->format($date_format) . ' - ' . $start->format($date_format) 18 . ' = ' . $start->diff($end)->format('PT%hH%iM%sS') . "\n"; 19 20$end = new DateTime('2010-03-14 04:30:00 -0400'); 21$start = new DateTime('2010-03-13 04:30:00 -0500'); 22echo 'fd2 ' . $end->format($date_format) . ' - ' . $start->format($date_format) 23 . ' = ' . $start->diff($end)->format($interval_format) . "\n"; 24 25$end = new DateTime('2010-03-14 03:30:00 -0400'); 26$start = new DateTime('2010-03-13 04:30:00 -0500'); 27echo 'fd3 ' . $end->format($date_format) . ' - ' . $start->format($date_format) 28 . ' = ' . $start->diff($end)->format($interval_format) . "\n"; 29 30$end = new DateTime('2010-03-14 01:30:00 -0500'); 31$start = new DateTime('2010-03-13 04:30:00 -0500'); 32echo 'fd4 ' . $end->format($date_format) . ' - ' . $start->format($date_format) 33 . ' = ' . $start->diff($end)->format($interval_format) . "\n"; 34 35$end = new DateTime('2010-03-14 01:30:00 -0500'); 36$start = new DateTime('2010-03-13 01:30:00 -0500'); 37echo 'fd5 ' . $end->format($date_format) . ' - ' . $start->format($date_format) 38 . ' = ' . $start->diff($end)->format($interval_format) . "\n"; 39 40$end = new DateTime('2010-03-14 03:30:00 -0400'); 41$start = new DateTime('2010-03-13 03:30:00 -0500'); 42echo 'fd6 ' . $end->format($date_format) . ' - ' . $start->format($date_format) 43 . ' = ' . $start->diff($end)->format($interval_format) . "\n"; 44 45$end = new DateTime('2010-03-14 03:30:00 -0400'); 46$start = new DateTime('2010-03-13 02:30:00 -0500'); 47echo 'fd7 ' . $end->format($date_format) . ' - ' . $start->format($date_format) 48 . ' = ' . $start->diff($end)->format($interval_format) . "\n"; 49 50echo "\n"; 51 52/* 53 * Forward Transitions, add(). 54 */ 55 56$start = new DateTime('2010-03-14 01:59:59 -0500'); 57$interval_spec = 'PT1S'; 58$interval = new DateInterval($interval_spec); 59echo 'fa1 ' . $start->format($date_format) . " + $interval_spec = " 60 . $start->add($interval)->format($date_format) . "\n"; 61 62$start = new DateTime('2010-03-13 04:30:00 -0500'); 63$interval_spec = 'P1D'; 64$interval = new DateInterval($interval_spec); 65echo 'fa2 ' . $start->format($date_format) . " + $interval_spec = " 66 . $start->add($interval)->format($date_format) . "\n"; 67 68$start = new DateTime('2010-03-13 04:30:00 -0500'); 69$interval_spec = 'PT22H'; 70$interval = new DateInterval($interval_spec); 71echo 'fa3 ' . $start->format($date_format) . " + $interval_spec = " 72 . $start->add($interval)->format($date_format) . "\n"; 73 74$start = new DateTime('2010-03-13 04:30:00 -0500'); 75$interval_spec = 'PT21H'; 76$interval = new DateInterval($interval_spec); 77echo 'fa4 ' . $start->format($date_format) . " + $interval_spec = " 78 . $start->add($interval)->format($date_format) . "\n"; 79 80$start = new DateTime('2010-03-13 01:30:00 -0500'); 81$interval_spec = 'P1D'; 82$interval = new DateInterval($interval_spec); 83echo 'fa5 ' . $start->format($date_format) . " + $interval_spec = " 84 . $start->add($interval)->format($date_format) . "\n"; 85 86$start = new DateTime('2010-03-13 02:30:00 -0500'); 87$interval_spec = 'P1D'; 88$interval = new DateInterval($interval_spec); 89echo 'fa6 ' . $start->format($date_format) . " + $interval_spec = " 90 . $start->add($interval)->format($date_format) . "\n"; 91 92echo "\n"; 93 94/* 95 * Forward Transitions, sub(). 96 */ 97 98$end = new DateTime('2010-03-14 03:00:00 -0400'); 99$interval_spec = 'PT1S'; 100$interval = new DateInterval($interval_spec); 101echo 'fs1 ' . $end->format($date_format) . " - $interval_spec = " 102 . $end->sub($interval)->format($date_format) . "\n"; 103 104$end = new DateTime('2010-03-14 04:30:00 -0400'); 105$interval_spec = 'P1D'; 106$interval = new DateInterval($interval_spec); 107echo 'fs2 ' . $end->format($date_format) . " - $interval_spec = " 108 . $end->sub($interval)->format($date_format) . "\n"; 109 110$end = new DateTime('2010-03-14 03:30:00 -0400'); 111$interval_spec = 'PT22H'; 112$interval = new DateInterval($interval_spec); 113echo 'fs3 ' . $end->format($date_format) . " - $interval_spec = " 114 . $end->sub($interval)->format($date_format) . "\n"; 115 116$end = new DateTime('2010-03-14 01:30:00 -0500'); 117$interval_spec = 'PT21H'; 118$interval = new DateInterval($interval_spec); 119echo 'fs4 ' . $end->format($date_format) . " - $interval_spec = " 120 . $end->sub($interval)->format($date_format) . "\n"; 121 122$end = new DateTime('2010-03-14 01:30:00 -0500'); 123$interval_spec = 'P1D'; 124$interval = new DateInterval($interval_spec); 125echo 'fs5 ' . $end->format($date_format) . " - $interval_spec = " 126 . $end->sub($interval)->format($date_format) . "\n"; 127 128$end = new DateTime('2010-03-15 03:30:00 -0400'); 129$interval_spec = 'P1D'; 130$interval = new DateInterval($interval_spec); 131echo 'fs6 ' . $end->format($date_format) . " - $interval_spec = " 132 . $end->sub($interval)->format($date_format) . "\n"; 133 134$end = new DateTime('2010-03-15 02:30:00 -0400'); 135$interval_spec = 'P1D'; 136$interval = new DateInterval($interval_spec); 137echo 'fs7 ' . $end->format($date_format) . " - $interval_spec = " 138 . $end->sub($interval)->format($date_format) . "\n"; 139 140echo "\n"; 141 142/* 143 * Backward Transitions, diff(). 144 */ 145$end = new DateTime('2010-11-07 01:00:00 -0500'); 146$start = new DateTime('2010-11-07 01:59:59 -0400'); 147echo 'bd1 ' . $end->format($date_format) . ' - ' . $start->format($date_format) 148 . ' = ' . $start->diff($end)->format('PT%hH%iM%sS') . "\n"; 149 150$end = new DateTime('2010-11-07 04:30:00 -0500'); 151$start = new DateTime('2010-11-06 04:30:00 -0400'); 152echo 'bd2 ' . $end->format($date_format) . ' - ' . $start->format($date_format) 153 . ' = ' . $start->diff($end)->format($interval_format) . "\n"; 154 155$end = new DateTime('2010-11-07 03:30:00 -0500'); 156$start = new DateTime('2010-11-06 04:30:00 -0400'); 157echo 'bd3 ' . $end->format($date_format) . ' - ' . $start->format($date_format) 158 . ' = ' . $start->diff($end)->format($interval_format) . "\n"; 159 160$end = new DateTime('2010-11-07 02:30:00 -0500'); 161$start = new DateTime('2010-11-06 04:30:00 -0400'); 162echo 'bd4 ' . $end->format($date_format) . ' - ' . $start->format($date_format) 163 . ' = ' . $start->diff($end)->format($interval_format) . "\n"; 164 165$end = new DateTime('2010-11-07 01:30:00 -0500'); 166$start = new DateTime('2010-11-06 04:30:00 -0400'); 167echo 'bd5 ' . $end->format($date_format) . ' - ' . $start->format($date_format) 168 . ' = ' . $start->diff($end)->format($interval_format) . "\n"; 169 170$end = new DateTime('2010-11-07 01:30:00 -0400'); 171$start = new DateTime('2010-11-06 04:30:00 -0400'); 172echo 'bd6 ' . $end->format($date_format) . ' - ' . $start->format($date_format) 173 . ' = ' . $start->diff($end)->format($interval_format) . "\n"; 174 175$end = new DateTime('2010-11-07 01:30:00 -0400'); 176$start = new DateTime('2010-11-06 01:30:00 -0400'); 177echo 'bd7 ' . $end->format($date_format) . ' - ' . $start->format($date_format) 178 . ' = ' . $start->diff($end)->format($interval_format) . "\n"; 179 180$end = new DateTime('2010-11-07 01:30:00 -0500'); 181$start = new DateTime('2010-11-06 01:30:00 -0400'); 182echo 'bd8 ' . $end->format($date_format) . ' - ' . $start->format($date_format) 183 . ' = ' . $start->diff($end)->format($interval_format) . "\n"; 184 185echo "\n"; 186 187/* 188 * Backward Transitions, add(). 189 */ 190 191$start = new DateTime('2010-11-07 01:59:59 -0400'); 192$interval_spec = 'PT1S'; 193$interval = new DateInterval($interval_spec); 194echo 'ba1 ' . $start->format($date_format) . " + $interval_spec = " 195 . $start->add($interval)->format($date_format) . "\n"; 196 197$start = new DateTime('2010-11-06 04:30:00 -0400'); 198$interval_spec = 'P1D'; 199$interval = new DateInterval($interval_spec); 200echo 'ba2 ' . $start->format($date_format) . " + $interval_spec = " 201 . $start->add($interval)->format($date_format) . "\n"; 202 203$start = new DateTime('2010-11-06 04:30:00 -0400'); 204$interval_spec = 'PT24H'; 205$interval = new DateInterval($interval_spec); 206echo 'ba3 ' . $start->format($date_format) . " + $interval_spec = " 207 . $start->add($interval)->format($date_format) . "\n"; 208 209$start = new DateTime('2010-11-06 04:30:00 -0400'); 210$interval_spec = 'PT23H'; 211$interval = new DateInterval($interval_spec); 212echo 'ba4 ' . $start->format($date_format) . " + $interval_spec = " 213 . $start->add($interval)->format($date_format) . "\n"; 214 215$start = new DateTime('2010-11-06 04:30:00 -0400'); 216$interval_spec = 'PT22H'; 217$interval = new DateInterval($interval_spec); 218echo 'ba5 ' . $start->format($date_format) . " + $interval_spec = " 219 . $start->add($interval)->format($date_format) . "\n"; 220 221$start = new DateTime('2010-11-06 04:30:00 -0400'); 222$interval_spec = 'PT21H'; 223$interval = new DateInterval($interval_spec); 224echo 'ba6 ' . $start->format($date_format) . " + $interval_spec = " 225 . $start->add($interval)->format($date_format) . "\n"; 226 227$start = new DateTime('2010-11-06 01:30:00 -0400'); 228$interval_spec = 'P1D'; 229$interval = new DateInterval($interval_spec); 230echo 'ba7 ' . $start->format($date_format) . " + $interval_spec = " 231 . $start->add($interval)->format($date_format) . "\n"; 232 233$start = new DateTime('2010-11-06 01:30:00 -0400'); 234$interval_spec = 'P1DT1H'; 235$interval = new DateInterval($interval_spec); 236echo 'ba8 ' . $start->format($date_format) . " + $interval_spec = " 237 . $start->add($interval)->format($date_format) . "\n"; 238 239$start = new DateTime('2010-11-06 04:30:00 -0400'); 240$interval_spec = 'PT25H'; 241$interval = new DateInterval($interval_spec); 242echo 'ba9 ' . $start->format($date_format) . " + $interval_spec = " 243 . $start->add($interval)->format($date_format) . "\n"; 244 245$start = new DateTime('2010-11-06 03:30:00 -0400'); 246$interval_spec = 'P1D'; 247$interval = new DateInterval($interval_spec); 248echo 'ba10 ' . $start->format($date_format) . " + $interval_spec = " 249 . $start->add($interval)->format($date_format) . "\n"; 250 251$start = new DateTime('2010-11-06 02:30:00 -0400'); 252$interval_spec = 'P1D'; 253$interval = new DateInterval($interval_spec); 254echo 'ba11 ' . $start->format($date_format) . " + $interval_spec = " 255 . $start->add($interval)->format($date_format) . "\n"; 256 257echo "\n"; 258 259/* 260 * Backward Transitions, sub(). 261 */ 262 263$end = new DateTime('2010-11-07 01:00:00 -0500'); 264$interval_spec = 'PT1S'; 265$interval = new DateInterval($interval_spec); 266echo 'bs1 ' . $end->format($date_format) . " - $interval_spec = " 267 . $end->sub($interval)->format($date_format) . "\n"; 268 269$end = new DateTime('2010-11-07 04:30:00 -0500'); 270$interval_spec = 'P1D'; 271$interval = new DateInterval($interval_spec); 272echo 'bs2 ' . $end->format($date_format) . " - $interval_spec = " 273 . $end->sub($interval)->format($date_format) . "\n"; 274 275$end = new DateTime('2010-11-07 03:30:00 -0500'); 276$interval_spec = 'PT24H'; 277$interval = new DateInterval($interval_spec); 278echo 'bs3 ' . $end->format($date_format) . " - $interval_spec = " 279 . $end->sub($interval)->format($date_format) . "\n"; 280 281$end = new DateTime('2010-11-07 02:30:00 -0500'); 282$interval_spec = 'PT23H'; 283$interval = new DateInterval($interval_spec); 284echo 'bs4 ' . $end->format($date_format) . " - $interval_spec = " 285 . $end->sub($interval)->format($date_format) . "\n"; 286 287$end = new DateTime('2010-11-07 01:30:00 -0500'); 288$interval_spec = 'PT22H'; 289$interval = new DateInterval($interval_spec); 290echo 'bs5 ' . $end->format($date_format) . " - $interval_spec = " 291 . $end->sub($interval)->format($date_format) . "\n"; 292 293$end = new DateTime('2010-11-07 01:30:00 -0400'); 294$interval_spec = 'PT21H'; 295$interval = new DateInterval($interval_spec); 296echo 'bs6 ' . $end->format($date_format) . " - $interval_spec = " 297 . $end->sub($interval)->format($date_format) . "\n"; 298 299$end = new DateTime('2010-11-07 01:30:00 -0400'); 300$interval_spec = 'P1D'; 301$interval = new DateInterval($interval_spec); 302echo 'bs7 ' . $end->format($date_format) . " - $interval_spec = " 303 . $end->sub($interval)->format($date_format) . "\n"; 304 305$end = new DateTime('2010-11-07 01:30:00 -0500'); 306$interval_spec = 'P1DT1H'; 307$interval = new DateInterval($interval_spec); 308echo 'bs8 ' . $end->format($date_format) . " - $interval_spec = " 309 . $end->sub($interval)->format($date_format) . "\n"; 310 311$end = new DateTime('2010-11-07 03:30:00 -0500'); 312$interval_spec = 'P1D'; 313$interval = new DateInterval($interval_spec); 314echo 'bs9 ' . $end->format($date_format) . " - $interval_spec = " 315 . $end->sub($interval)->format($date_format) . "\n"; 316 317$end = new DateTime('2010-11-07 02:30:00 -0500'); 318$interval_spec = 'P1D'; 319$interval = new DateInterval($interval_spec); 320echo 'bs10 ' . $end->format($date_format) . " - $interval_spec = " 321 . $end->sub($interval)->format($date_format) . "\n"; 322 323?> 324--EXPECT-- 325fd1 2010-03-14 03:00:00 -04:00 - 2010-03-14 01:59:59 -05:00 = PT0H0M1S 326fd2 2010-03-14 04:30:00 -04:00 - 2010-03-13 04:30:00 -05:00 = P0DT23H 327fd3 2010-03-14 03:30:00 -04:00 - 2010-03-13 04:30:00 -05:00 = P0DT22H 328fd4 2010-03-14 01:30:00 -05:00 - 2010-03-13 04:30:00 -05:00 = P0DT21H 329fd5 2010-03-14 01:30:00 -05:00 - 2010-03-13 01:30:00 -05:00 = P1DT0H 330fd6 2010-03-14 03:30:00 -04:00 - 2010-03-13 03:30:00 -05:00 = P0DT23H 331fd7 2010-03-14 03:30:00 -04:00 - 2010-03-13 02:30:00 -05:00 = P1DT0H 332 333fa1 2010-03-14 01:59:59 -05:00 + PT1S = 2010-03-14 02:00:00 -05:00 334fa2 2010-03-13 04:30:00 -05:00 + P1D = 2010-03-14 04:30:00 -05:00 335fa3 2010-03-13 04:30:00 -05:00 + PT22H = 2010-03-14 02:30:00 -05:00 336fa4 2010-03-13 04:30:00 -05:00 + PT21H = 2010-03-14 01:30:00 -05:00 337fa5 2010-03-13 01:30:00 -05:00 + P1D = 2010-03-14 01:30:00 -05:00 338fa6 2010-03-13 02:30:00 -05:00 + P1D = 2010-03-14 02:30:00 -05:00 339 340fs1 2010-03-14 03:00:00 -04:00 - PT1S = 2010-03-14 02:59:59 -04:00 341fs2 2010-03-14 04:30:00 -04:00 - P1D = 2010-03-13 04:30:00 -04:00 342fs3 2010-03-14 03:30:00 -04:00 - PT22H = 2010-03-13 05:30:00 -04:00 343fs4 2010-03-14 01:30:00 -05:00 - PT21H = 2010-03-13 04:30:00 -05:00 344fs5 2010-03-14 01:30:00 -05:00 - P1D = 2010-03-13 01:30:00 -05:00 345fs6 2010-03-15 03:30:00 -04:00 - P1D = 2010-03-14 03:30:00 -04:00 346fs7 2010-03-15 02:30:00 -04:00 - P1D = 2010-03-14 02:30:00 -04:00 347 348bd1 2010-11-07 01:00:00 -05:00 - 2010-11-07 01:59:59 -04:00 = PT0H0M1S 349bd2 2010-11-07 04:30:00 -05:00 - 2010-11-06 04:30:00 -04:00 = P1DT1H 350bd3 2010-11-07 03:30:00 -05:00 - 2010-11-06 04:30:00 -04:00 = P1DT0H 351bd4 2010-11-07 02:30:00 -05:00 - 2010-11-06 04:30:00 -04:00 = P0DT23H 352bd5 2010-11-07 01:30:00 -05:00 - 2010-11-06 04:30:00 -04:00 = P0DT22H 353bd6 2010-11-07 01:30:00 -04:00 - 2010-11-06 04:30:00 -04:00 = P0DT21H 354bd7 2010-11-07 01:30:00 -04:00 - 2010-11-06 01:30:00 -04:00 = P1DT0H 355bd8 2010-11-07 01:30:00 -05:00 - 2010-11-06 01:30:00 -04:00 = P1DT1H 356 357ba1 2010-11-07 01:59:59 -04:00 + PT1S = 2010-11-07 02:00:00 -04:00 358ba2 2010-11-06 04:30:00 -04:00 + P1D = 2010-11-07 04:30:00 -04:00 359ba3 2010-11-06 04:30:00 -04:00 + PT24H = 2010-11-07 04:30:00 -04:00 360ba4 2010-11-06 04:30:00 -04:00 + PT23H = 2010-11-07 03:30:00 -04:00 361ba5 2010-11-06 04:30:00 -04:00 + PT22H = 2010-11-07 02:30:00 -04:00 362ba6 2010-11-06 04:30:00 -04:00 + PT21H = 2010-11-07 01:30:00 -04:00 363ba7 2010-11-06 01:30:00 -04:00 + P1D = 2010-11-07 01:30:00 -04:00 364ba8 2010-11-06 01:30:00 -04:00 + P1DT1H = 2010-11-07 02:30:00 -04:00 365ba9 2010-11-06 04:30:00 -04:00 + PT25H = 2010-11-07 05:30:00 -04:00 366ba10 2010-11-06 03:30:00 -04:00 + P1D = 2010-11-07 03:30:00 -04:00 367ba11 2010-11-06 02:30:00 -04:00 + P1D = 2010-11-07 02:30:00 -04:00 368 369bs1 2010-11-07 01:00:00 -05:00 - PT1S = 2010-11-07 00:59:59 -05:00 370bs2 2010-11-07 04:30:00 -05:00 - P1D = 2010-11-06 04:30:00 -05:00 371bs3 2010-11-07 03:30:00 -05:00 - PT24H = 2010-11-06 03:30:00 -05:00 372bs4 2010-11-07 02:30:00 -05:00 - PT23H = 2010-11-06 03:30:00 -05:00 373bs5 2010-11-07 01:30:00 -05:00 - PT22H = 2010-11-06 03:30:00 -05:00 374bs6 2010-11-07 01:30:00 -04:00 - PT21H = 2010-11-06 04:30:00 -04:00 375bs7 2010-11-07 01:30:00 -04:00 - P1D = 2010-11-06 01:30:00 -04:00 376bs8 2010-11-07 01:30:00 -05:00 - P1DT1H = 2010-11-06 00:30:00 -05:00 377bs9 2010-11-07 03:30:00 -05:00 - P1D = 2010-11-06 03:30:00 -05:00 378bs10 2010-11-07 02:30:00 -05:00 - P1D = 2010-11-06 02:30:00 -05:00 379