xref: /PHP-5.5/ext/date/tests/date_add_basic.phpt (revision a9e5e222)
1--TEST--
2Test date_add() function : basic functionality
3--CREDITS--
4Felix De Vliegher <felix.devliegher@gmail.com>
5--SKIPIF--
6<?php if (!function_exists('date_add')) echo "skip: date_add() function not found!"; ?>
7--FILE--
8<?php
9date_default_timezone_set('UTC');
10/* Prototype  : void date_add(DateTime object, DateInterval interval)
11 * Description: Adds an interval to the current date in object.
12 * Source code: ext/date/php_date.c
13 * Alias to functions:
14 */
15
16echo "*** Testing date_add() : basic functionality ***\n";
17
18// Initialise all required variables
19$startDate = '2008-01-01 12:25';
20$format = 'Y-m-d H:i:s';
21$intervals = array(
22	'P3Y6M4DT12H30M5S',
23	'P0D',
24	'P2DT1M',
25	'P1Y2MT23H43M150S'
26);
27
28$d = new DateTime($startDate);
29var_dump( $d->format($format) );
30
31foreach($intervals as $interval) {
32	date_add($d, new DateInterval($interval) );
33	var_dump( $d->format($format) );
34}
35
36?>
37===DONE===
38--EXPECTF--
39*** Testing date_add() : basic functionality ***
40string(19) "2008-01-01 12:25:00"
41string(19) "2011-07-06 00:55:05"
42string(19) "2011-07-06 00:55:05"
43string(19) "2011-07-08 00:56:05"
44string(19) "2012-09-09 00:41:35"
45===DONE===
46