Req #66610 [Nab]: +1 Month on Leap Year

From: Date: Thu, 30 Jan 2014 22:15:29 +0000
Subject: Req #66610 [Nab]: +1 Month on Leap Year
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-184096@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=66610&edit=1 ID: 66610 User updated by: me at jacobt dot com Reported by: me at jacobt dot com Summary: +1 Month on Leap Year Status: Not a bug Type: Feature/Change Request Package: Date/time related Operating System: Centos 6 PHP Version: 5.5.9RC1 Block user comment: N Private report: N New Comment: Rasmus, your suggested solution to this issue is certainly fitting and acceptable - thank you for that. As for the handling of the string "+1 Month", while I do understand the reasoning and logic behind it, I find it flawed, regardless of what GNU or any other platform is currently doing to this effect. Granted, yes, it makes sense from a technical and mathematical perspective, logically it does not make sense. I challenge you to ask any random "normal" person what their take is on it. I would be very hard pressed to buy into the notion that they would come up with dates like March 2nd or March 3rd. I understand that the alternative approach would have similar results for a set of up to 2-3 days, depending, however, that's perfectly acceptable. It doesn't need to be unique. As you state, there isn't necessarily a defined way to handle it, and a month isn't a constant. However, there are wrong ways to handle it and I find this to be one of those cases and any other platform that handles it similarly. I'd challenge you to step back and take an objective view of this, ask random people and consider a fix. As for the suggested solution - that works perfectly and will use that right away and in the future. It solves my problems, but still leaves flawed logic IMHO. Thanks for all the work and cheers! Previous Comments: ------------------------------------------------------------------------ [2014-01-30 09:53:47] rasmus@php.net There is no right way here. We follow the GNU standard on this one as does many, if not most, other UNIX utils which means when you say you want to add a month, we increment the month, then adjust to make sure this falls on a valid date. Feb.30 is not valid, but it is 2 days after Feb.28 which is March 2. If we didn't do this when adding a month to Jan.28, Jan.29 and Jan.30 would all give you the same result. Try the same in sqlite or even from your Linux command line: $ date --date='+1 month' +'Next month is %B?' Next month is March? See: http://www.gnu.org/software/tar/manual/html_node/Relative-items-in-date-strings.html#SEC120 The solution is to be more specific about what you actually want. If you want the last day of next month, then say so. eg. "last day of next month" or "first day of next month" ------------------------------------------------------------------------ [2014-01-30 08:01:10] me at jacobt dot com Description: ------------ Please check out the following example... http://codepad.viper-7.com/1Scqvd I'm not sure who thought this was the right thing to do, but it's not. For how MySQL handles it... mysql> SELECT DATE_ADD('2009-01-30', INTERVAL 1 MONTH); -> '2009-02-28' I find that more acceptable. Or, what I would actually prefer is March 1. If you're going to add time, which is basically what you're doing here b/c a month isn't a set number of days, add the minimum number required to get the job done, no more than that... Test script: --------------- http://codepad.viper-7.com/1Scqvd Expected result: ---------------- It should be clear in the file and description ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=66610&edit=1

« previous php.bugs (#184096) next »