xref: /PHP-7.1/ext/date/tests/date_sub_basic.phpt (revision 7af945e2)
1--TEST--
2Test date_sub() function : basic functionality
3--CREDITS--
4Felix De Vliegher <felix.devliegher@gmail.com>
5--SKIPIF--
6<?php if (!function_exists('date_sub')) echo "skip: date_sub() function not found!"; ?>
7--FILE--
8<?php
9date_default_timezone_set('UTC');
10/* Prototype  : void date_sub(DateTime object, DateInterval interval)
11 * Description: Subtracts an interval from the current date in object.
12 * Source code: ext/date/php_date.c
13 * Alias to functions:
14 */
15
16echo "*** Testing date_sub() : 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_sub($d, new DateInterval($interval) );
33	var_dump( $d->format($format) );
34}
35
36?>
37===DONE===
38--EXPECTF--
39*** Testing date_sub() : basic functionality ***
40string(19) "2008-01-01 12:25:00"
41string(19) "2004-06-26 23:54:55"
42string(19) "2004-06-26 23:54:55"
43string(19) "2004-06-24 23:53:55"
44string(19) "2003-04-24 00:08:25"
45===DONE===
46