Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:88114 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 29328 invoked from network); 8 Sep 2015 04:55:20 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Sep 2015 04:55:20 -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.181 as permitted sender) X-PHP-List-Original-Sender: yohgaki@gmail.com X-Host-Fingerprint: 209.85.160.181 mail-yk0-f181.google.com Received: from [209.85.160.181] ([209.85.160.181:34821] helo=mail-yk0-f181.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D9/68-34134-63A6EE55 for ; Tue, 08 Sep 2015 00:55:19 -0400 Received: by ykdu9 with SMTP id u9so26482660ykd.2 for ; Mon, 07 Sep 2015 21:55:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:from:date:message-id:subject:to:content-type; bh=hU45B2lqnYXsdo/8PAWUAkuK5LD3abkit1F2CQyqRYk=; b=g3nRU9WU800yanoaRdPg4iRWOaAYHm7Y4RdidzzgomxelBjaRRJ6YvdckFnAyS0JYe UwfnFAxLOifQALd+2cUjovatx4zGAsS3pLDsToRuYTGW4X8cN3FEWaTfQoH+zT0dextu FH/KJGFpBV6qmCY5wGOsuA2dghBS/mvtHUKliJ1XsgjC3tywIMi4n1UigYypW78G4D9T jFy5/ptzrTFRv2wekIAMUhHxWFo8ht4QbKmKErhaJAa4YVSepheOWlQMUhVSSaNkYauX cVEJZYd31/rxCVMPwQOkkcS7dgVLGMSwIjBntbiekbraPcHVss0psrfXgfL1pz/sdnQA k/KQ== X-Received: by 10.13.206.67 with SMTP id q64mr26066318ywd.154.1441688115669; Mon, 07 Sep 2015 21:55:15 -0700 (PDT) MIME-Version: 1.0 Sender: yohgaki@gmail.com Received: by 10.129.57.215 with HTTP; Mon, 7 Sep 2015 21:54:36 -0700 (PDT) Date: Tue, 8 Sep 2015 13:54:36 +0900 X-Google-Sender-Auth: Fy_xw5m-miudmHLTnwn6gLUgguY Message-ID: To: "internals@lists.php.net" , Derick Rethans Content-Type: text/plain; charset=UTF-8 Subject: Invalid date/time handling - strtotime() From: yohgaki@ohgaki.net (Yasuo Ohgaki) Hi Derick and all, strtotime() may be improved. $ php -r "echo date('Y-m-d',strtotime('00-00-00 00:00:00'));" 1999-11-30 because 00 is 2000, 00 month is -1(=12) and 00 date is -1(last date of previous month). This is unintuitive result at a glance. strtotime() handles date/time edge cases and produces reasonable timestamp in some cases. $ php -r "echo date('Y-m-d H:i:s',strtotime('00-01-01 24:00:00'));" 2000-01-02 00:00:00 $ php -r "echo date('Y-m-d H:i:s',strtotime('03-02-29 00:00:00'));" 2003-03-01 00:00:00 $ php -r "echo date('Y-m-d H:i:s',strtotime('03-02-28 23:59:60'));" 2003-03-01 00:00:00 It returns FALSE for larger values exceeds edge cases. For example, $ php -r "var_dump(strtotime('03-02-32 00:00:00'));" bool(false) Somehow it does not accept 13 month while it is edge case. $ php -r "var_dump(strtotime('03-13-30 00:00:00'));" bool(false) It does not accept day 32 while it accepts 2/31. $ php -r "var_dump(strtotime('03-01-32 00:00:00'));" bool(false) $ php -r "var_dump(strtotime('03-02-31 00:00:00'));" int(1046617200) 25 hour/60 minutes is invalid also. $ php -r "var_dump(strtotime('03-02-31 00:60:00'));" bool(false) $ php -r "var_dump(strtotime('03-02-31 25:00:00'));" bool(false) It seems edge case handling is inconsistent. How about make strtotime() - Accept all edge cases by default. - Add $strict flag as 2nd parameter and reject any invalid date/time. (Do not allow leap second also? Some system may create 60th second) Alternatively, we may be strict - Disallow all edge cases by default. (There may be problem with leap second) Any comments? Reference: https://bugs.php.net/bug.php?id=45647 -- Yasuo Ohgaki yohgaki@ohgaki.net