date_create-relative.phpt 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. --TEST--
  2. date_create() with large relative offsets
  3. --FILE--
  4. <?php
  5. date_default_timezone_set('UTC');
  6. if (!defined('PHP_INT_MIN')) {
  7. define('PHP_INT_MIN', intval(-PHP_INT_MAX - 1));
  8. }
  9. $base_time = '28 Feb 2008 12:00:00';
  10. // Most offsets tested in strtotime-relative.phpt. These are tests for dates outside the 32-bit range.
  11. $offsets = array(
  12. // around 10 leap year periods (4000 years) in days
  13. '1460000 days',
  14. '1460969 days',
  15. '1460970 days',
  16. '1460971 days',
  17. '1462970 days',
  18. // around 1 leap year period in years
  19. '398 years',
  20. '399 years',
  21. '400 years',
  22. '401 years',
  23. // around 40000 years
  24. '39755 years',
  25. '39999 years',
  26. '40000 years',
  27. '40001 years',
  28. '41010 years',
  29. // bigger than int (32-bit)
  30. '10000000000 seconds',
  31. '10000000000 minutes',
  32. '10000000000 hours',
  33. '10000000000 days',
  34. '10000000000 months',
  35. '10000000000 years',
  36. );
  37. foreach ($offsets AS $offset) {
  38. foreach (array('+', '-') AS $direction) {
  39. $dt = date_create("$base_time $direction$offset");
  40. echo "$direction$offset: " . date_format($dt, DATE_ISO8601) . "\n";
  41. }
  42. }
  43. ?>
  44. --EXPECT--
  45. +1460000 days: 6005-07-03T12:00:00+0000
  46. -1460000 days: -1990-10-25T12:00:00+0000
  47. +1460969 days: 6008-02-27T12:00:00+0000
  48. -1460969 days: -1992-02-29T12:00:00+0000
  49. +1460970 days: 6008-02-28T12:00:00+0000
  50. -1460970 days: -1992-02-28T12:00:00+0000
  51. +1460971 days: 6008-02-29T12:00:00+0000
  52. -1460971 days: -1992-02-27T12:00:00+0000
  53. +1462970 days: 6013-08-20T12:00:00+0000
  54. -1462970 days: -1998-09-07T12:00:00+0000
  55. +398 years: 2406-02-28T12:00:00+0000
  56. -398 years: 1610-02-28T12:00:00+0000
  57. +399 years: 2407-02-28T12:00:00+0000
  58. -399 years: 1609-02-28T12:00:00+0000
  59. +400 years: 2408-02-28T12:00:00+0000
  60. -400 years: 1608-02-28T12:00:00+0000
  61. +401 years: 2409-02-28T12:00:00+0000
  62. -401 years: 1607-02-28T12:00:00+0000
  63. +39755 years: 41763-02-28T12:00:00+0000
  64. -39755 years: -37747-02-28T12:00:00+0000
  65. +39999 years: 42007-02-28T12:00:00+0000
  66. -39999 years: -37991-02-28T12:00:00+0000
  67. +40000 years: 42008-02-28T12:00:00+0000
  68. -40000 years: -37992-02-28T12:00:00+0000
  69. +40001 years: 42009-02-28T12:00:00+0000
  70. -40001 years: -37993-02-28T12:00:00+0000
  71. +41010 years: 43018-02-28T12:00:00+0000
  72. -41010 years: -39002-02-28T12:00:00+0000
  73. +10000000000 seconds: 2325-01-18T05:46:40+0000
  74. -10000000000 seconds: 1691-04-09T18:13:20+0000
  75. +10000000000 minutes: 21021-05-27T22:40:00+0000
  76. -10000000000 minutes: -17006-12-01T01:20:00+0000
  77. +10000000000 hours: 1142802-09-30T04:00:00+0000
  78. -10000000000 hours: -1138787-07-28T20:00:00+0000
  79. +10000000000 days: 27381078-03-25T12:00:00+0000
  80. -10000000000 days: -27377062-02-02T12:00:00+0000
  81. +10000000000 months: 833335341-06-28T12:00:00+0000
  82. -10000000000 months: -833331326-10-28T12:00:00+0000
  83. +10000000000 years: 10000002008-02-28T12:00:00+0000
  84. -10000000000 years: -9999997992-02-28T12:00:00+0000