danielc Wed, 13 Jul 2011 16:08:03 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=313208
Log: Use datetime examine diff file from 5.3 in 5.4 and trunk. Changed paths: U php/php-src/branches/PHP_5_4/ext/date/tests/examine_diff.inc U php/php-src/trunk/ext/date/tests/examine_diff.inc Modified: php/php-src/branches/PHP_5_4/ext/date/tests/examine_diff.inc =================================================================== --- php/php-src/branches/PHP_5_4/ext/date/tests/examine_diff.inc 2011-07-13 15:13:10 UTC (rev 313207) +++ php/php-src/branches/PHP_5_4/ext/date/tests/examine_diff.inc 2011-07-13 16:08:03 UTC (rev 313208) @@ -1,17 +1,23 @@ <?php /** - * Helper for the DateTime_diff_add_sub* tests + * Helper for the DateTime diff/days/math tests * * @author Daniel Convissor <dani...@analysisandsolutions.com> */ +/**#@+ + * Which test segments should be displayed? + */ +define('PHPT_DATETIME_SHOW_DIFF', 1); +define('PHPT_DATETIME_SHOW_DAYS', 2); +define('PHPT_DATETIME_SHOW_ADD', 3); +define('PHPT_DATETIME_SHOW_SUB', 4); +/**#@-*/ + /** - * Provides a consistent interface for executing date diff tests + * Provides a consistent interface for executing date diff/add/sub tests * - * Tests the diff() method then passes the resulting - * interval to the add()/sub() method as a double check - * * @param string|DateTime $end_date the end date in YYYY-MM-DD format * (can include time HH:MM:SS) or a DateTime object * @param string|DateTime $start_date the start date in YYYY-MM-DD format @@ -41,38 +47,33 @@ } $end_date = $end->format('Y-m-d H:i:s T'); - $force_sub = false; - if ($absolute) { - $tmp_interval = $start->diff($end); - if ($tmp_interval->format('%r')) { - $force_sub = true; - } + $expect_interval = new DateInterval('P' . substr($expect_spec, 2)); + if (substr($expect_spec, 1, 1) == '-') { + $expect_interval->invert = true; } - $result_interval = $start->diff($end, $absolute); - $result_spec = $result_interval->format('P%R%yY%mM%dDT%hH%iM%sS'); - $result_days = $result_interval->format('%a'); - - // Also make sure add()/sub() works the same way as diff(). - if ($force_sub) { - $start->sub($result_interval); - $sign = '-'; - } else { - $start->add($result_interval); - $sign = '+'; + if (PHPT_DATETIME_SHOW == PHPT_DATETIME_SHOW_DIFF) { + $result_interval = $start->diff($end, $absolute); + $result_spec = $result_interval->format('P%R%yY%mM%dDT%hH%iM%sS'); + echo "DIFF: $end_date - $start_date = **$result_spec**\n"; + // echo "DIFF: $end_date - $start_date = **$expect_spec**\n"; } - - $result_end_date = $start->format('Y-m-d H:i:s T'); - - // Leaving this here for making adjustments later. - $expect_full = "FWD: $end_date - $start_date = **$expect_spec** | " - . "BACK: $start_date $sign $expect_spec = **$end_date** | " - . "DAYS: **$expect_days**"; - // echo "$expect_full\n"; - // return; - - $result_full = "FWD: $end_date - $start_date = **$result_spec** | " - . "BACK: $start_date $sign $result_spec = **$result_end_date** | " - . "DAYS: **$result_days**"; - echo "$result_full\n"; + if (PHPT_DATETIME_SHOW == PHPT_DATETIME_SHOW_DAYS) { + $result_interval = $start->diff($end, $absolute); + $result_days = $result_interval->format('%a'); + echo "DAYS: **$result_days**\n"; + // echo "DAYS: **$expect_days**\n"; + } + if (PHPT_DATETIME_SHOW == PHPT_DATETIME_SHOW_ADD) { + $start->add($expect_interval); + $result_end_date = $start->format('Y-m-d H:i:s T'); + echo "ADD: $start_date + $expect_spec = **$result_end_date**\n"; + // echo "ADD: $start_date + $expect_spec = **$end_date**\n"; + } + if (PHPT_DATETIME_SHOW == PHPT_DATETIME_SHOW_SUB) { + $end->sub($expect_interval); + $result_start_date = $end->format('Y-m-d H:i:s T'); + echo "SUB: $end_date - $expect_spec = **$result_start_date**\n"; + // echo "SUB: $end_date - $expect_spec = **$start_date**\n"; + } } Modified: php/php-src/trunk/ext/date/tests/examine_diff.inc =================================================================== --- php/php-src/trunk/ext/date/tests/examine_diff.inc 2011-07-13 15:13:10 UTC (rev 313207) +++ php/php-src/trunk/ext/date/tests/examine_diff.inc 2011-07-13 16:08:03 UTC (rev 313208) @@ -1,17 +1,23 @@ <?php /** - * Helper for the DateTime_diff_add_sub* tests + * Helper for the DateTime diff/days/math tests * * @author Daniel Convissor <dani...@analysisandsolutions.com> */ +/**#@+ + * Which test segments should be displayed? + */ +define('PHPT_DATETIME_SHOW_DIFF', 1); +define('PHPT_DATETIME_SHOW_DAYS', 2); +define('PHPT_DATETIME_SHOW_ADD', 3); +define('PHPT_DATETIME_SHOW_SUB', 4); +/**#@-*/ + /** - * Provides a consistent interface for executing date diff tests + * Provides a consistent interface for executing date diff/add/sub tests * - * Tests the diff() method then passes the resulting - * interval to the add()/sub() method as a double check - * * @param string|DateTime $end_date the end date in YYYY-MM-DD format * (can include time HH:MM:SS) or a DateTime object * @param string|DateTime $start_date the start date in YYYY-MM-DD format @@ -41,38 +47,33 @@ } $end_date = $end->format('Y-m-d H:i:s T'); - $force_sub = false; - if ($absolute) { - $tmp_interval = $start->diff($end); - if ($tmp_interval->format('%r')) { - $force_sub = true; - } + $expect_interval = new DateInterval('P' . substr($expect_spec, 2)); + if (substr($expect_spec, 1, 1) == '-') { + $expect_interval->invert = true; } - $result_interval = $start->diff($end, $absolute); - $result_spec = $result_interval->format('P%R%yY%mM%dDT%hH%iM%sS'); - $result_days = $result_interval->format('%a'); - - // Also make sure add()/sub() works the same way as diff(). - if ($force_sub) { - $start->sub($result_interval); - $sign = '-'; - } else { - $start->add($result_interval); - $sign = '+'; + if (PHPT_DATETIME_SHOW == PHPT_DATETIME_SHOW_DIFF) { + $result_interval = $start->diff($end, $absolute); + $result_spec = $result_interval->format('P%R%yY%mM%dDT%hH%iM%sS'); + echo "DIFF: $end_date - $start_date = **$result_spec**\n"; + // echo "DIFF: $end_date - $start_date = **$expect_spec**\n"; } - - $result_end_date = $start->format('Y-m-d H:i:s T'); - - // Leaving this here for making adjustments later. - $expect_full = "FWD: $end_date - $start_date = **$expect_spec** | " - . "BACK: $start_date $sign $expect_spec = **$end_date** | " - . "DAYS: **$expect_days**"; - // echo "$expect_full\n"; - // return; - - $result_full = "FWD: $end_date - $start_date = **$result_spec** | " - . "BACK: $start_date $sign $result_spec = **$result_end_date** | " - . "DAYS: **$result_days**"; - echo "$result_full\n"; + if (PHPT_DATETIME_SHOW == PHPT_DATETIME_SHOW_DAYS) { + $result_interval = $start->diff($end, $absolute); + $result_days = $result_interval->format('%a'); + echo "DAYS: **$result_days**\n"; + // echo "DAYS: **$expect_days**\n"; + } + if (PHPT_DATETIME_SHOW == PHPT_DATETIME_SHOW_ADD) { + $start->add($expect_interval); + $result_end_date = $start->format('Y-m-d H:i:s T'); + echo "ADD: $start_date + $expect_spec = **$result_end_date**\n"; + // echo "ADD: $start_date + $expect_spec = **$end_date**\n"; + } + if (PHPT_DATETIME_SHOW == PHPT_DATETIME_SHOW_SUB) { + $end->sub($expect_interval); + $result_start_date = $end->format('Y-m-d H:i:s T'); + echo "SUB: $end_date - $expect_spec = **$result_start_date**\n"; + // echo "SUB: $end_date - $expect_spec = **$start_date**\n"; + } }
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php