xref: /PHP-8.2/ext/date/tests/date_add_basic.phpt (revision b5c7a83d)
1--TEST--
2Test date_add() function : basic functionality
3--CREDITS--
4Felix De Vliegher <felix.devliegher@gmail.com>
5--FILE--
6<?php
7date_default_timezone_set('UTC');
8echo "*** Testing date_add() : basic functionality ***\n";
9
10// Initialise all required variables
11$startDate = '2008-01-01 12:25';
12$format = 'Y-m-d H:i:s';
13$intervals = array(
14    'P3Y6M4DT12H30M5S',
15    'P0D',
16    'P2DT1M',
17    'P1Y2MT23H43M150S'
18);
19
20$d = new DateTime($startDate);
21var_dump( $d->format($format) );
22
23foreach($intervals as $interval) {
24    date_add($d, new DateInterval($interval) );
25    var_dump( $d->format($format) );
26}
27
28?>
29--EXPECT--
30*** Testing date_add() : basic functionality ***
31string(19) "2008-01-01 12:25:00"
32string(19) "2011-07-06 00:55:05"
33string(19) "2011-07-06 00:55:05"
34string(19) "2011-07-08 00:56:05"
35string(19) "2012-09-09 00:41:35"
36