--TEST-- Test Bug #49081 (DateTime::diff() mistake if start in January and interval > 28 days) --SKIPIF-- --INI-- date.timezone=GMT --FILE-- diff($end); $actual = $interval->format('P%R%yY%mM%dD%hH%iM%sS'); echo "$end_date - $start_date = $actual"; if ($actual != $expected) { // Yeah, this is gratuitous, but it helps clarify // what's going on in the test and the diff. echo " (expected: $expected)"; } echo "\n"; } echo "March (a month with 31 days followed by a month with fewer days)...\n"; calc('2010-03-31', '2010-03-01', 'P+0Y0M30D0H0M0S'); echo "March into April...\n"; calc('2010-04-01', '2010-03-01', 'P+0Y1M0D0H0M0S'); calc('2010-04-01', '2010-03-31', 'P+0Y0M1D0H0M0S'); calc('2010-04-29', '2010-03-31', 'P+0Y0M29D0H0M0S'); calc('2010-04-30', '2010-03-31', 'P+0Y0M30D0H0M0S'); calc('2010-04-30', '2010-03-30', 'P+0Y1M0D0H0M0S'); calc('2010-04-30', '2010-03-29', 'P+0Y1M1D0H0M0S'); echo "January 2010 (a month of 31 days followed by 28 days)...\n"; calc('2010-01-29', '2010-01-01', 'P+0Y0M28D0H0M0S'); calc('2010-01-30', '2010-01-01', 'P+0Y0M29D0H0M0S'); calc('2010-01-31', '2010-01-01', 'P+0Y0M30D0H0M0S'); echo "January into February...\n"; calc('2010-02-01', '2010-01-01', 'P+0Y1M0D0H0M0S'); calc('2010-02-01', '2010-01-31', 'P+0Y0M1D0H0M0S'); calc('2010-02-27', '2010-01-31', 'P+0Y0M27D0H0M0S'); calc('2010-02-28', '2010-01-31', 'P+0Y0M28D0H0M0S'); calc('2010-02-28', '2010-01-30', 'P+0Y0M29D0H0M0S'); calc('2010-02-28', '2010-01-29', 'P+0Y0M30D0H0M0S'); calc('2010-02-28', '2010-01-28', 'P+0Y1M0D0H0M0S'); calc('2010-02-28', '2010-01-27', 'P+0Y1M1D0H0M0S'); echo "January into March...\n"; calc('2010-03-01', '2010-01-01', 'P+0Y2M0D0H0M0S'); calc('2010-03-01', '2010-01-31', 'P+0Y1M1D0H0M0S'); calc('2010-03-27', '2010-01-31', 'P+0Y1M27D0H0M0S'); calc('2010-03-28', '2010-01-31', 'P+0Y1M28D0H0M0S'); calc('2010-03-29', '2010-01-31', 'P+0Y1M29D0H0M0S'); calc('2010-03-30', '2010-01-31', 'P+0Y1M30D0H0M0S'); calc('2010-03-31', '2010-01-31', 'P+0Y2M0D0H0M0S'); calc('2010-03-31', '2010-01-30', 'P+0Y2M1D0H0M0S'); echo "January 2009 (to ensure the 2010 isn't the issue)...\n"; calc('2009-01-31', '2009-01-01', 'P+0Y0M30D0H0M0S'); ?> ===DONE=== --EXPECT-- March (a month with 31 days followed by a month with fewer days)... 2010-03-31 - 2010-03-01 = P+0Y0M30D0H0M0S March into April... 2010-04-01 - 2010-03-01 = P+0Y1M0D0H0M0S 2010-04-01 - 2010-03-31 = P+0Y0M1D0H0M0S 2010-04-29 - 2010-03-31 = P+0Y0M29D0H0M0S 2010-04-30 - 2010-03-31 = P+0Y0M30D0H0M0S 2010-04-30 - 2010-03-30 = P+0Y1M0D0H0M0S 2010-04-30 - 2010-03-29 = P+0Y1M1D0H0M0S January 2010 (a month of 31 days followed by 28 days)... 2010-01-29 - 2010-01-01 = P+0Y0M28D0H0M0S 2010-01-30 - 2010-01-01 = P+0Y0M29D0H0M0S 2010-01-31 - 2010-01-01 = P+0Y0M30D0H0M0S January into February... 2010-02-01 - 2010-01-01 = P+0Y1M0D0H0M0S 2010-02-01 - 2010-01-31 = P+0Y0M1D0H0M0S 2010-02-27 - 2010-01-31 = P+0Y0M27D0H0M0S 2010-02-28 - 2010-01-31 = P+0Y0M28D0H0M0S 2010-02-28 - 2010-01-30 = P+0Y0M29D0H0M0S 2010-02-28 - 2010-01-29 = P+0Y0M30D0H0M0S 2010-02-28 - 2010-01-28 = P+0Y1M0D0H0M0S 2010-02-28 - 2010-01-27 = P+0Y1M1D0H0M0S January into March... 2010-03-01 - 2010-01-01 = P+0Y2M0D0H0M0S 2010-03-01 - 2010-01-31 = P+0Y1M1D0H0M0S 2010-03-27 - 2010-01-31 = P+0Y1M27D0H0M0S 2010-03-28 - 2010-01-31 = P+0Y1M28D0H0M0S 2010-03-29 - 2010-01-31 = P+0Y1M29D0H0M0S 2010-03-30 - 2010-01-31 = P+0Y1M30D0H0M0S 2010-03-31 - 2010-01-31 = P+0Y2M0D0H0M0S 2010-03-31 - 2010-01-30 = P+0Y2M1D0H0M0S January 2009 (to ensure the 2010 isn't the issue)... 2009-01-31 - 2009-01-01 = P+0Y0M30D0H0M0S ===DONE===