mike            Mon Mar  5 14:05:31 2007 UTC

  Modified files:              
    /php-src/ext/date   php_date.c 
  Log:
  - fix bug #40691: add comparison object handler
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/date/php_date.c?r1=1.131&r2=1.132&diff_format=u
Index: php-src/ext/date/php_date.c
diff -u php-src/ext/date/php_date.c:1.131 php-src/ext/date/php_date.c:1.132
--- php-src/ext/date/php_date.c:1.131   Wed Feb 14 19:35:01 2007
+++ php-src/ext/date/php_date.c Mon Mar  5 14:05:31 2007
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: php_date.c,v 1.131 2007/02/14 19:35:01 derick Exp $ */
+/* $Id: php_date.c,v 1.132 2007/03/05 14:05:31 mike Exp $ */
 
 #include "php.h"
 #include "php_streams.h"
@@ -300,6 +300,7 @@
 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 */ 
@@ -1589,6 +1590,7 @@
        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);
@@ -1660,6 +1662,27 @@
        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(o2->time, o2->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;

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to