xref: /PHP-7.3/ext/date/tests/date_add_basic.phpt (revision 782352c5)
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');
8/* Prototype  : void date_add(DateTime object, DateInterval interval)
9 * Description: Adds an interval to the current date in object.
10 * Source code: ext/date/php_date.c
11 * Alias to functions:
12 */
13
14echo "*** Testing date_add() : basic functionality ***\n";
15
16// Initialise all required variables
17$startDate = '2008-01-01 12:25';
18$format = 'Y-m-d H:i:s';
19$intervals = array(
20	'P3Y6M4DT12H30M5S',
21	'P0D',
22	'P2DT1M',
23	'P1Y2MT23H43M150S'
24);
25
26$d = new DateTime($startDate);
27var_dump( $d->format($format) );
28
29foreach($intervals as $interval) {
30	date_add($d, new DateInterval($interval) );
31	var_dump( $d->format($format) );
32}
33
34?>
35===DONE===
36--EXPECT--
37*** Testing date_add() : basic functionality ***
38string(19) "2008-01-01 12:25:00"
39string(19) "2011-07-06 00:55:05"
40string(19) "2011-07-06 00:55:05"
41string(19) "2011-07-08 00:56:05"
42string(19) "2012-09-09 00:41:35"
43===DONE===
44