xref: /PHP-8.0/ext/date/tests/bug49059.phpt (revision 02e46447)
1--TEST--
2Bug #49059 (DateTime::diff() repeats previous sub() operation)
3--FILE--
4<?php
5date_default_timezone_set('Asia/Calcutta');
6
7$date1 = date_create("2009-03-27");
8$date2 = date_create("2009-03-01");
9print "\$date1 at init: " . $date1->format("Y-m-d") . "\n";
10print "\$date2 at init: " . $date2->format("Y-m-d") . "\n";
11$diff = $date1->diff($date2);
12print "\$date1 after first diff: " . $date1->format("Y-m-d") . "\n";
13print "\$diff->days after first diff: " . $diff->days . "\n";
14$date1 = $date1->sub(new DateInterval("P2D"));
15print "\$date1 after sub: " . $date1->format("Y-m-d") . "\n";
16$diff = $date1->diff($date2);
17print "\$date1 after second diff (called at \$date1): " .
18$date1->format("Y-m-d") . "\n";
19print "\$diff->days after second diff: " . $diff->days . "\n";
20$diff = $date2->diff($date1);
21print "\$date1 after third diff (called at \$date2): " .
22$date1->format("Y-m-d") . "\n";
23print "\$diff->days after third diff: " . $diff->days . "\n";
24?>
25--EXPECT--
26$date1 at init: 2009-03-27
27$date2 at init: 2009-03-01
28$date1 after first diff: 2009-03-27
29$diff->days after first diff: 26
30$date1 after sub: 2009-03-25
31$date1 after second diff (called at $date1): 2009-03-25
32$diff->days after second diff: 24
33$date1 after third diff (called at $date2): 2009-03-25
34$diff->days after third diff: 24
35