DateTime_data-dates.inc 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /*
  3. * Note: test names match method names in a set of PHPUnit tests
  4. * in a userland package. Please be so kind as to leave them.
  5. */
  6. date_default_timezone_set('America/New_York');
  7. /*
  8. * Particular days
  9. */
  10. echo "test__7: ";
  11. examine_diff('2009-01-14', '2009-01-07', 'P+0Y0M7DT0H0M0S', 7);
  12. echo "test_years_positive__7_by_0_day: ";
  13. examine_diff('2007-02-07', '2000-02-07', 'P+7Y0M0DT0H0M0S', 2557);
  14. echo "test_years_positive__7_by_1_day: ";
  15. examine_diff('2007-02-08', '2000-02-07', 'P+7Y0M1DT0H0M0S', 2558);
  16. // NOTE: sub() produces different answer.
  17. echo "test_years_positive__6_shy_1_day: ";
  18. examine_diff('2007-02-06', '2000-02-07', 'P+6Y11M30DT0H0M0S', 2556);
  19. echo "test_years_positive__7_by_1_month: ";
  20. examine_diff('2007-03-07', '2000-02-07', 'P+7Y1M0DT0H0M0S', 2585);
  21. echo "test_years_positive__6_shy_1_month: ";
  22. examine_diff('2007-01-07', '2000-02-07', 'P+6Y11M0DT0H0M0S', 2526);
  23. echo "test_years_positive__7_by_1_month_split_newyear: ";
  24. examine_diff('2007-01-07', '1999-12-07', 'P+7Y1M0DT0H0M0S', 2588);
  25. echo "test_years_positive__6_shy_1_month_split_newyear: ";
  26. examine_diff('2006-12-07', '2000-01-07', 'P+6Y11M0DT0H0M0S', 2526);
  27. /*
  28. * Particular days, negative
  29. */
  30. echo "test_negative__7: ";
  31. examine_diff('2009-01-07', '2009-01-14', 'P-0Y0M7DT0H0M0S', 7);
  32. echo "test_years_negative__7_by_0_day: ";
  33. examine_diff('2000-02-07', '2007-02-07', 'P-7Y0M0DT0H0M0S', 2557);
  34. echo "test_years_negative__7_by_1_day: ";
  35. examine_diff('2000-02-07', '2007-02-08', 'P-7Y0M1DT0H0M0S', 2558);
  36. // NOTE: sub() produces different answer.
  37. echo "test_years_negative__6_shy_1_day: ";
  38. examine_diff('2000-02-07', '2007-02-06', 'P-6Y11M28DT0H0M0S', 2556);
  39. echo "test_years_negative__7_by_1_month: ";
  40. examine_diff('2000-02-07', '2007-03-07', 'P-7Y1M0DT0H0M0S', 2585);
  41. echo "test_years_negative__6_shy_1_month: ";
  42. examine_diff('2000-02-07', '2007-01-07', 'P-6Y11M0DT0H0M0S', 2526);
  43. echo "test_years_negative__7_by_1_month_split_newyear: ";
  44. examine_diff('1999-12-07', '2007-01-07', 'P-7Y1M0DT0H0M0S', 2588);
  45. echo "test_years_negative__6_shy_1_month_split_newyear: ";
  46. examine_diff('2000-01-07', '2006-12-07', 'P-6Y11M0DT0H0M0S', 2526);