date_sub_basic.phpt 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. --TEST--
  2. Test date_sub() function : basic functionality
  3. --CREDITS--
  4. Felix De Vliegher <felix.devliegher@gmail.com>
  5. --FILE--
  6. <?php
  7. date_default_timezone_set('UTC');
  8. /* Prototype : void date_sub(DateTime object, DateInterval interval)
  9. * Description: Subtracts an interval from the current date in object.
  10. * Source code: ext/date/php_date.c
  11. * Alias to functions:
  12. */
  13. echo "*** Testing date_sub() : basic functionality ***\n";
  14. // Initialise all required variables
  15. $startDate = '2008-01-01 12:25';
  16. $format = 'Y-m-d H:i:s';
  17. $intervals = array(
  18. 'P3Y6M4DT12H30M5S',
  19. 'P0D',
  20. 'P2DT1M',
  21. 'P1Y2MT23H43M150S'
  22. );
  23. $d = new DateTime($startDate);
  24. var_dump( $d->format($format) );
  25. foreach($intervals as $interval) {
  26. date_sub($d, new DateInterval($interval) );
  27. var_dump( $d->format($format) );
  28. }
  29. ?>
  30. ===DONE===
  31. --EXPECT--
  32. *** Testing date_sub() : basic functionality ***
  33. string(19) "2008-01-01 12:25:00"
  34. string(19) "2004-06-26 23:54:55"
  35. string(19) "2004-06-26 23:54:55"
  36. string(19) "2004-06-24 23:53:55"
  37. string(19) "2003-04-24 00:08:25"
  38. ===DONE===