Back to index

php5  5.3.10
examine_diff.inc
Go to the documentation of this file.
00001 <?php
00002 
00012 define('PHPT_DATETIME_SHOW_DIFF', 1);
00013 define('PHPT_DATETIME_SHOW_DAYS', 2);
00014 define('PHPT_DATETIME_SHOW_ADD', 3);
00015 define('PHPT_DATETIME_SHOW_SUB', 4);
00035 function examine_diff($end_date, $start_date, $expect_spec, $expect_days, $absolute = false) {
00036        if (is_string($start_date)) {
00037               $start = new DateTime($start_date);
00038        } else {
00039               $start = $start_date;
00040        }
00041        $start_date = $start->format('Y-m-d H:i:s T');
00042 
00043        if (is_string($end_date)) {
00044               $end = new DateTime($end_date);
00045        } else {
00046               $end = $end_date;
00047        }
00048        $end_date = $end->format('Y-m-d H:i:s T');
00049 
00050        $expect_interval = new DateInterval('P' . substr($expect_spec, 2));
00051        if (substr($expect_spec, 1, 1) == '-') {
00052               $expect_interval->invert = true;
00053        }
00054 
00055        if (PHPT_DATETIME_SHOW == PHPT_DATETIME_SHOW_DIFF) {
00056               $result_interval = $start->diff($end, $absolute);
00057               $result_spec = $result_interval->format('P%R%yY%mM%dDT%hH%iM%sS');
00058               echo "DIFF: $end_date - $start_date = **$result_spec**\n";
00059               // echo "DIFF: $end_date - $start_date = **$expect_spec**\n";
00060        }
00061        if (PHPT_DATETIME_SHOW == PHPT_DATETIME_SHOW_DAYS) {
00062               $result_interval = $start->diff($end, $absolute);
00063               $result_days = $result_interval->format('%a');
00064               echo "DAYS: **$result_days**\n";
00065               // echo "DAYS: **$expect_days**\n";
00066        }
00067        if (PHPT_DATETIME_SHOW == PHPT_DATETIME_SHOW_ADD) {
00068               $start->add($expect_interval);
00069               $result_end_date = $start->format('Y-m-d H:i:s T');
00070               echo "ADD: $start_date + $expect_spec = **$result_end_date**\n";
00071               // echo "ADD: $start_date + $expect_spec = **$end_date**\n";
00072        }
00073        if (PHPT_DATETIME_SHOW == PHPT_DATETIME_SHOW_SUB) {
00074               $end->sub($expect_interval);
00075               $result_start_date = $end->format('Y-m-d H:i:s T');
00076               echo "SUB: $end_date - $expect_spec = **$result_start_date**\n";
00077               // echo "SUB: $end_date - $expect_spec = **$start_date**\n";
00078        }
00079 }