strtotime-relative.phpt 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. --TEST--
  2. strtotime() with relative offsets
  3. --FILE--
  4. <?php
  5. date_default_timezone_set('UTC');
  6. $base_time = 1204200000; // 28 Feb 2008 12:00:00
  7. $offsets = array(
  8. // offset around a day
  9. '80412 seconds',
  10. '86399 seconds',
  11. '86400 seconds',
  12. '86401 seconds',
  13. '112913 seconds',
  14. // offset around 7 days
  15. '134 hours',
  16. '167 hours',
  17. '168 hours',
  18. '169 hours',
  19. '183 hours',
  20. // offset around 6 months
  21. '178 days',
  22. '179 days',
  23. '180 days',
  24. '183 days',
  25. '184 days',
  26. // offset around 10 years
  27. '115 months',
  28. '119 months',
  29. '120 months',
  30. '121 months',
  31. '128 months',
  32. // offset around 25 years (can't do much more reliably with strtotime)
  33. '24 years',
  34. '25 years',
  35. '26 years'
  36. );
  37. foreach ($offsets AS $offset) {
  38. foreach (array('+', '-') AS $direction) {
  39. echo "$direction$offset: " . date(DATE_ISO8601, strtotime("$direction$offset", $base_time)) . "\n";
  40. }
  41. }
  42. ?>
  43. --EXPECT--
  44. +80412 seconds: 2008-02-29T10:20:12+0000
  45. -80412 seconds: 2008-02-27T13:39:48+0000
  46. +86399 seconds: 2008-02-29T11:59:59+0000
  47. -86399 seconds: 2008-02-27T12:00:01+0000
  48. +86400 seconds: 2008-02-29T12:00:00+0000
  49. -86400 seconds: 2008-02-27T12:00:00+0000
  50. +86401 seconds: 2008-02-29T12:00:01+0000
  51. -86401 seconds: 2008-02-27T11:59:59+0000
  52. +112913 seconds: 2008-02-29T19:21:53+0000
  53. -112913 seconds: 2008-02-27T04:38:07+0000
  54. +134 hours: 2008-03-05T02:00:00+0000
  55. -134 hours: 2008-02-22T22:00:00+0000
  56. +167 hours: 2008-03-06T11:00:00+0000
  57. -167 hours: 2008-02-21T13:00:00+0000
  58. +168 hours: 2008-03-06T12:00:00+0000
  59. -168 hours: 2008-02-21T12:00:00+0000
  60. +169 hours: 2008-03-06T13:00:00+0000
  61. -169 hours: 2008-02-21T11:00:00+0000
  62. +183 hours: 2008-03-07T03:00:00+0000
  63. -183 hours: 2008-02-20T21:00:00+0000
  64. +178 days: 2008-08-24T12:00:00+0000
  65. -178 days: 2007-09-03T12:00:00+0000
  66. +179 days: 2008-08-25T12:00:00+0000
  67. -179 days: 2007-09-02T12:00:00+0000
  68. +180 days: 2008-08-26T12:00:00+0000
  69. -180 days: 2007-09-01T12:00:00+0000
  70. +183 days: 2008-08-29T12:00:00+0000
  71. -183 days: 2007-08-29T12:00:00+0000
  72. +184 days: 2008-08-30T12:00:00+0000
  73. -184 days: 2007-08-28T12:00:00+0000
  74. +115 months: 2017-09-28T12:00:00+0000
  75. -115 months: 1998-07-28T12:00:00+0000
  76. +119 months: 2018-01-28T12:00:00+0000
  77. -119 months: 1998-03-28T12:00:00+0000
  78. +120 months: 2018-02-28T12:00:00+0000
  79. -120 months: 1998-02-28T12:00:00+0000
  80. +121 months: 2018-03-28T12:00:00+0000
  81. -121 months: 1998-01-28T12:00:00+0000
  82. +128 months: 2018-10-28T12:00:00+0000
  83. -128 months: 1997-06-28T12:00:00+0000
  84. +24 years: 2032-02-28T12:00:00+0000
  85. -24 years: 1984-02-28T12:00:00+0000
  86. +25 years: 2033-02-28T12:00:00+0000
  87. -25 years: 1983-02-28T12:00:00+0000
  88. +26 years: 2034-02-28T12:00:00+0000
  89. -26 years: 1982-02-28T12:00:00+0000