Bug #68981 [NEW]: negative relative month values in strtime() give nonsense results

From: Date: Tue, 03 Feb 2015 18:36:02 +0000
Subject: Bug #68981 [NEW]: negative relative month values in strtime() give nonsense results
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-190445@lists.php.net to get a copy of this message
From:             teo8976 at gmail dot com
Operating system: linux
PHP version:      5.6.5
Package:          Date/time related
Bug Type:         Bug
Bug description:negative relative month values in strtime() give nonsense results

Description:
------------
The way negative relative month values are handled by strtotime() is
1) undocumented
2) complete nonsense

example: strtotime("-3 months", $date)

Test script:
---------------
$end_date=mktime(23,59,59,12,31,2014);
echo date("r", $end_date)."\n";
$date=strtotime("-1 months", $end_date);
echo date("r", $date)."\n";
$date=strtotime("-2 months", $end_date);
echo date("r", $date)."\n";
$date=strtotime("-3 months", $end_date);
echo date("r", $date)."\n";
$date=strtotime("-4 months", $end_date);
echo date("r", $date)."\n";
$date=strtotime("-5 months", $end_date);
echo date("r", $date)."\n";
$date=strtotime("-6 months", $end_date);
echo date("r", $date)."\n";
$date=strtotime("-7 months", $end_date);
echo date("r", $date)."\n";
$date=strtotime("-8 months", $end_date);
echo date("r", $date)."\n";
$date=strtotime("-9 months", $end_date);
echo date("r", $date)."\n";
$date=strtotime("-10 months", $end_date);
echo date("r", $date)."\n";
$date=strtotime("-11 months", $end_date);
echo date("r", $date)."\n";
$date=strtotime("-12 months", $end_date);
echo date("r", $date)."\n";

Expected result:
----------------
Wed, 31 Dec 2014 23:59:59 +0100
Mon, 30 Nov 2014 23:59:59 +0100
Fri, 31 Oct 2014 23:59:59 +0100
Wed, 30 Sep 2014 23:59:59 +0200
Sun, 31 Aug 2014 23:59:59 +0200
Thu, 31 Jul 2014 23:59:59 +0200
Tue, 30 Jun 2014 23:59:59 +0200
Sat, 31 May 2014 23:59:59 +0200
Thu, 30 Apr 2014 23:59:59 +0200
Mon, 31 Mar 2014 23:59:59 +0200
Mon, 28 Feb 2014 23:59:59 +0100
Fri, 31 Jan 2014 23:59:59 +0100
Tue, 31 Dec 2013 23:59:59 +0100

Actual result:
--------------
Wed, 31 Dec 2014 23:59:59 +0100
Mon, 01 Dec 2014 23:59:59 +0100
Fri, 31 Oct 2014 23:59:59 +0100
Wed, 01 Oct 2014 23:59:59 +0200
Sun, 31 Aug 2014 23:59:59 +0200
Thu, 31 Jul 2014 23:59:59 +0200
Tue, 01 Jul 2014 23:59:59 +0200
Sat, 31 May 2014 23:59:59 +0200
Thu, 01 May 2014 23:59:59 +0200
Mon, 31 Mar 2014 23:59:59 +0200
Mon, 03 Mar 2014 23:59:59 +0100 << THIS IS PARTICULARLY HILARIOUS
Fri, 31 Jan 2014 23:59:59 +0100
Tue, 31 Dec 2013 23:59:59 +0100

-- 
Edit bug report at https://bugs.php.net/bug.php?id=68981&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=68981&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=68981&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=68981&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=68981&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=68981&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=68981&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=68981&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=68981&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=68981&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=68981&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=68981&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=68981&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=68981&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=68981&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=68981&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=68981&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=68981&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=68981&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=68981&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=68981&r=mysqlcfg



Thread (7 messages)

« previous php.bugs (#190445) next »