Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:88120 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 6278 invoked from network); 8 Sep 2015 21:23:06 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Sep 2015 21:23:06 -0000 Authentication-Results: pb1.pair.com header.from=yohgaki@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=yohgaki@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.160.175 as permitted sender) X-PHP-List-Original-Sender: yohgaki@gmail.com X-Host-Fingerprint: 209.85.160.175 mail-yk0-f175.google.com Received: from [209.85.160.175] ([209.85.160.175:34642] helo=mail-yk0-f175.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 87/E3-10366-8B15FE55 for ; Tue, 08 Sep 2015 17:23:04 -0400 Received: by ykdg206 with SMTP id g206so139709703ykd.1 for ; Tue, 08 Sep 2015 14:23:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=40NqeIjqa/n3VWFKncbk9/6C9ZPUSy8HP5u0R0QN1AI=; b=P90zsACzYeHipOy4zarf6G4xalmjlr9KFUcDCRPK7yowudWDMzOakIhtDKCwlAhlXf yaNudWrJxpfCTT9+PxafuBQKQrMUBc4vDu9Umgm4MCmGluHcinBhZZUgEcEY97a3E+NZ Cf+oPABk1n0axePRnAI6BnW0IdPIbY/Y+HNi4HVQ4Vp7lBh8dCa3BexNR7DA7MowR83m 2Fi0F1f7pkM6McPqnbIC3mQbrzMgMWmejgrQ2TB7VWx3hRt5tti66OWUxBJei6ytZAG4 py55lYTyVlG34woQhO3+uXmRTLJo5clsFCP0EShSBs5ryEQryISrq7zvGt3zgafJI1GT Y3JQ== X-Received: by 10.129.51.88 with SMTP id z85mr33326542ywz.148.1441747381925; Tue, 08 Sep 2015 14:23:01 -0700 (PDT) MIME-Version: 1.0 Sender: yohgaki@gmail.com Received: by 10.129.57.215 with HTTP; Tue, 8 Sep 2015 14:22:22 -0700 (PDT) In-Reply-To: References: Date: Wed, 9 Sep 2015 06:22:22 +0900 X-Google-Sender-Auth: hb4teLD-cJuJfmygAZ170gn8MzE Message-ID: To: Derick Rethans Cc: "internals@lists.php.net" Content-Type: text/plain; charset=UTF-8 Subject: Re: Invalid date/time handling - strtotime() From: yohgaki@ohgaki.net (Yasuo Ohgaki) Hi Derick, On Wed, Sep 9, 2015 at 1:31 AM, Derick Rethans wrote: > Currently, it works as follows by design: > > - the parser, allows for each unit (year, month, day, hour, minute, > second) the full range of values. For a year that's just 4 digits, for > a month that's 0-12, day is 0-31 and for hour and minute it's 0-59. > > - 60 is allowed for seconds, as sometimes date strings with that > leapsecond do show up. But PHP implements Unix time where "60" is not > a valid second number and hence it overflows. There is some more > background information at http://drck.me/leapsec-6ye > > - strtotime() returns false if any number is outside of the ranges, and > new DateTime() throws an exception. > > - the parser is dumb, and doesn't do any checks to make it faster (and > more generic) > > - *but*, there is an additional check if you pass in an invalid date > (like your suggested $strict): > > $ php -r '$res = date_parse("2015-09-31"); var_dump($res["warnings"]);' > > array(1) { > [11] => > string(27) "The parsed date was invalid" > } > > - It is already possible to handle the edge cases, but then you need to > supply the right format. Otherwise there are too many possible > confusing and unintuitive results coming out of the parser: > > php -r '$res = date_create_from_format("Y-m-d", "2015-09-34"); var_dump($res);' > > class DateTime#1 (3) { > public $date => > string(26) "2015-10-04 17:24:43.000000" > public $timezone_type => > int(3) > public $timezone => > string(13) "Europe/London" > } > > - We can't add a second argument to strtotime(), because it already > exists. > > - Having a "strict" option to strtotime() does also not work, as that > would mean two distinct parsing routines. > > With all those concerns, as well as functionality to handle edge cases > in place, I do not think we should change anything. Thank you for detailed explanation. I'm OK with current design/API. How about add documentation for more precise date/time parsing and handling to strtotime() manual page? One concern is "0000-00-00" date. MySQL uses it as invalid date and strtotime() produces non intuitive result. It should be added to the document also. I made a bug report to track this. https://bugs.php.net/bug.php?id=70463 Regards, -- Yasuo Ohgaki yohgaki@ohgaki.net