Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:82575 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 26113 invoked from network); 13 Feb 2015 04:04:26 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 Feb 2015 04:04:26 -0000 Authentication-Results: pb1.pair.com smtp.mail=yohgaki@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=yohgaki@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.179 as permitted sender) X-PHP-List-Original-Sender: yohgaki@gmail.com X-Host-Fingerprint: 209.85.216.179 mail-qc0-f179.google.com Received: from [209.85.216.179] ([209.85.216.179:54721] helo=mail-qc0-f179.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 0C/30-23345-7C77DD45 for ; Thu, 12 Feb 2015 23:04:24 -0500 Received: by mail-qc0-f179.google.com with SMTP id r5so12137947qcx.10 for ; Thu, 12 Feb 2015 20:04:21 -0800 (PST) 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=ublqlrmxk3t85kjMI+hpxwUx5mHzZoentNyY+qeVknY=; b=na3kTHTeryapfqjV0wlP+4az3awAax/Fjw9zoVWYfIycQZBQaJ6sqG2y5t0YhvTRHe ah/J/9FyFbhSlWFsQPMFD9OUAUX5NJ0OqsgRcRibI92//9HmCklznOte9IjFt6TBHTmq /qIjudnalv4OX+7oiIpi5b39X8sAWrtZRvSG6i/MAMlRM3rA0xXl1nbEGZhujGpzmpHq rn3Kvw/r1pPdzwVe99iVWr+UtWjRDJ+FPSXwPmVIl21JWVRhXHC2bFmwYq9zfmqrrwVm M3C4z0iYajYn3sdz12jzLfbAdMKTN0Fg9i2iD6nT0io8KkmPlGSUuOYiF1qvcxodM4DL 8Osg== X-Received: by 10.140.42.83 with SMTP id b77mr18405892qga.43.1423800261202; Thu, 12 Feb 2015 20:04:21 -0800 (PST) MIME-Version: 1.0 Sender: yohgaki@gmail.com Received: by 10.229.198.8 with HTTP; Thu, 12 Feb 2015 20:03:40 -0800 (PST) Date: Fri, 13 Feb 2015 13:03:40 +0900 X-Google-Sender-Auth: D9m-Rfz5OqzkkrX8uRw9_87kUwc Message-ID: To: "internals@lists.php.net" , Derick Rethans Content-Type: multipart/alternative; boundary=001a11c13054ccd808050ef05410 Subject: Legal date generated from illegal date From: yohgaki@ohgaki.net (Yasuo Ohgaki) --001a11c13054ccd808050ef05410 Content-Type: text/plain; charset=UTF-8 Hi Derick, I came across with strange DataTime generates legal date from illegal date. http://3v4l.org/rKFIg format('Y-m-d H:i:s')); $date = new DateTime('0000-01-00'); var_dump($date->format('Y-m-d H:i:s')); $date = new DateTime('0000-00-01'); // "-0001-12-01 00:00:00" legal date from illegal date var_dump($date->format('Y-m-d H:i:s')); $date = new DateTime('0000-01-01'); var_dump($date->format('Y-m-d H:i:s')); $date = new DateTime('0001-00-00'); var_dump($date->format('Y-m-d H:i:s')); // "-0002-11-30 00:00:00" legal date from illegal $date = new DateTime('0001-01-00'); var_dump($date->format('Y-m-d H:i:s')); // "-0002-12-31 00:00:00" legal date from illegal $date = new DateTime('0001-00-01'); var_dump($date->format('Y-m-d H:i:s')); // "-0002-12-01 00:00:00" legal date from illegal $date = new DateTime('-0001-00-00'); var_dump($date->format('Y-m-d H:i:s')); // "-0002-11-30 00:00:00" legal date from illegal $date = new DateTime('-0001-01-00'); var_dump($date->format('Y-m-d H:i:s')); // "-0002-12-31 00:00:00" legal date from illegal $date = new DateTime('-0001-00-01'); var_dump($date->format('Y-m-d H:i:s')); // "-0002-12-01 00:00:00" legal date from illegal $date = new DateTime('0001-01-01'); // Correct date var_dump($date->format('Y-m-d H:i:s')); $date = new DateTime('-0001-01-01'); // Correct date var_dump($date->format('Y-m-d H:i:s')); ?> DateTime raises exceptions like month 13 or day 32, but not for some illegal dates. It seems this behavior is fixed/changed in 5.2.4 partially. I was about to report this behavior as a bug, but I thought it may be better to ask here the reason why it behaves like this. Is there reason that some illegal dates are allowed and result in strange date? One reason I can think of is MySQL. MySQL converts illegal date to 0000-00-00. All the above script's output is out of MySQL DateTime/TimeStamp range, so they are converted 0000-00-00 under MySQL. Even if PHP DateTime supports 0000-00-00 as invalid date, why don't make it return 0000-00-00 when input is 0000-00-00? Since these illegal dates are rather obvious, I thought there might be some reasons behind. ext/date/tests/bug41523-64bit.phpt ext/date/tests/bug41523.phpt These 2 tests use 0000-00-00 and expects the strange date. ext/date/tests/bug62852_var3.phpt This test unseliaizes 0000-00-00 date and raises exception. I see controversial behavior here, unserialize raises error while new DateTime('0000-00-00') doesn't. If it's a bug, I'll just file it as a bug. Thank you. Regards, -- Yasuo Ohgaki yohgaki@ohgaki.net --001a11c13054ccd808050ef05410--