Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:28243 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 78605 invoked by uid 1010); 5 Mar 2007 13:50:58 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 78590 invoked from network); 5 Mar 2007 13:50:58 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Mar 2007 13:50:58 -0000 X-Host-Fingerprint: 80.123.98.46 unknown Received: from [80.123.98.46] ([80.123.98.46:18102] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E4/E7-16561-1402CE54 for ; Mon, 05 Mar 2007 08:50:58 -0500 Message-ID: To: internals@lists.php.net Date: Mon, 05 Mar 2007 14:51:03 +0100 User-Agent: Thunderbird 1.5.0.9 (X11/20070103) MIME-Version: 1.0 References: <5E.95.16561.DC91CE54@pb1.pair.com> In-Reply-To: <5E.95.16561.DC91CE54@pb1.pair.com> Content-Type: multipart/mixed; boundary="------------030501080000080900000702" X-Posted-By: 80.123.98.46 Subject: Re: DateTime object equality From: mike@php.net (Michael Wallner) --------------030501080000080900000702 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Michael Wallner wrote: > Hans Lellelid wrote: > >> Is this DateTime comparison behavior actually intended to be different >> from everything else? If there's some reason that DateTime object >> properties cannot be compared to each other, wouldn't it be more >> appropriate for them to always return FALSE ? > > In my POV this is easily solvable with a custom comparison object handler. > See attached patch. I also think that comparing to Datetime instances should > give a reasonable result. > > Regards, -- Michael --------------030501080000080900000702 Content-Type: text/plain; name="date-cmp.diff.txt" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="date-cmp.diff.txt" Index: ext/date/php_date.c =================================================================== RCS file: /repository/php-src/ext/date/php_date.c,v retrieving revision 1.43.2.45.2.41 diff -u -p -d -r1.43.2.45.2.41 php_date.c --- ext/date/php_date.c 27 Feb 2007 03:04:39 -0000 1.43.2.45.2.41 +++ ext/date/php_date.c 5 Mar 2007 13:19:28 -0000 @@ -297,6 +297,7 @@ static void date_object_free_storage_tim static zend_object_value date_object_new_date(zend_class_entry *class_type TSRMLS_DC); static zend_object_value date_object_new_timezone(zend_class_entry *class_type TSRMLS_DC); static zend_object_value date_object_clone_date(zval *this_ptr TSRMLS_DC); +static int date_object_compare_date(zval *d1, zval *d2 TSRMLS_DC); static zend_object_value date_object_clone_timezone(zval *this_ptr TSRMLS_DC); /* This is need to ensure that session extension request shutdown occurs 1st, because it uses the date extension */ @@ -1459,6 +1460,7 @@ static void date_register_classes(TSRMLS date_ce_date = zend_register_internal_class_ex(&ce_date, NULL, NULL TSRMLS_CC); memcpy(&date_object_handlers_date, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); date_object_handlers_date.clone_obj = date_object_clone_date; + date_object_handlers_date.compare_objects = date_object_compare_date; #define REGISTER_DATE_CLASS_CONST_STRING(const_name, value) \ zend_declare_class_constant_stringl(date_ce_date, const_name, sizeof(const_name)-1, value, sizeof(value)-1 TSRMLS_CC); @@ -1530,6 +1532,27 @@ static zend_object_value date_object_clo return new_ov; } +static int date_object_compare_date(zval *d1, zval *d2 TSRMLS_DC) +{ + if ( Z_TYPE_P(d1) == IS_OBJECT && Z_TYPE_P(d2) == IS_OBJECT && + instanceof_function(Z_OBJCE_P(d1), date_ce_date TSRMLS_CC) && + instanceof_function(Z_OBJCE_P(d2), date_ce_date TSRMLS_CC)) { + php_date_obj *o1 = zend_object_store_get_object(d1 TSRMLS_CC); + php_date_obj *o2 = zend_object_store_get_object(d2 TSRMLS_CC); + + if (!o1->time->sse_uptodate) { + timelib_update_ts(o1->time, o1->time->tz_info); + } + if (!o2->time->sse_uptodate) { + timelib_update_ts(o1->time, o1->time->tz_info); + } + + return o1->time->sse == o2->time->sse ? 0 : o1->time->sse < o2->time->sse ? -1 : 1; + } + + return 1; +} + static inline zend_object_value date_object_new_timezone_ex(zend_class_entry *class_type, php_timezone_obj **ptr TSRMLS_DC) { php_timezone_obj *intern; --------------030501080000080900000702--