File tree Expand file tree Collapse file tree 2 files changed +49
-0
lines changed Expand file tree Collapse file tree 2 files changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -427,6 +427,25 @@ phongo_create_object_retval php_phongo_timestamp_create_object(zend_class_entry
427
427
#endif
428
428
} /* }}} */
429
429
430
+ static int php_phongo_timestamp_compare_objects (zval * o1 , zval * o2 TSRMLS_DC ) /* {{{ */
431
+ {
432
+ php_phongo_timestamp_t * intern1 , * intern2 ;
433
+
434
+ intern1 = Z_TIMESTAMP_OBJ_P (o1 );
435
+ intern2 = Z_TIMESTAMP_OBJ_P (o2 );
436
+
437
+ /* MongoDB compares the timestamp before the increment. */
438
+ if (intern1 -> timestamp != intern2 -> timestamp ) {
439
+ return intern1 -> timestamp < intern2 -> timestamp ? -1 : 1 ;
440
+ }
441
+
442
+ if (intern1 -> increment != intern2 -> increment ) {
443
+ return intern1 -> increment < intern2 -> increment ? -1 : 1 ;
444
+ }
445
+
446
+ return 0 ;
447
+ } /* }}} */
448
+
430
449
HashTable * php_phongo_timestamp_get_properties (zval * object TSRMLS_DC ) /* {{{ */
431
450
{
432
451
php_phongo_timestamp_t * intern ;
@@ -490,6 +509,7 @@ PHP_MINIT_FUNCTION(Timestamp)
490
509
zend_class_implements (php_phongo_timestamp_ce TSRMLS_CC , 1 , zend_ce_serializable );
491
510
492
511
memcpy (& php_phongo_handler_timestamp , phongo_get_std_object_handlers (), sizeof (zend_object_handlers ));
512
+ php_phongo_handler_timestamp .compare_objects = php_phongo_timestamp_compare_objects ;
493
513
php_phongo_handler_timestamp .get_properties = php_phongo_timestamp_get_properties ;
494
514
#if PHP_VERSION_ID >= 70000
495
515
php_phongo_handler_timestamp .free_obj = php_phongo_timestamp_free_object ;
Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ MongoDB\BSON\Timestamp comparisons
3
+ --FILE--
4
+ <?php
5
+
6
+ var_dump (new MongoDB \BSON \Timestamp (1234 , 5678 ) == new MongoDB \BSON \Timestamp (1234 , 5678 ));
7
+ var_dump (new MongoDB \BSON \Timestamp (1234 , 5678 ) < new MongoDB \BSON \Timestamp (1234 , 5678 ));
8
+ var_dump (new MongoDB \BSON \Timestamp (1234 , 5678 ) > new MongoDB \BSON \Timestamp (1234 , 5678 ));
9
+
10
+ // Timestamp is compared first
11
+ var_dump (new MongoDB \BSON \Timestamp (1234 , 5678 ) < new MongoDB \BSON \Timestamp (1233 , 5679 ));
12
+ var_dump (new MongoDB \BSON \Timestamp (1234 , 5678 ) > new MongoDB \BSON \Timestamp (1235 , 5677 ));
13
+
14
+ // Increment is compared second
15
+ var_dump (new MongoDB \BSON \Timestamp (1234 , 5678 ) < new MongoDB \BSON \Timestamp (1235 , 5678 ));
16
+ var_dump (new MongoDB \BSON \Timestamp (1234 , 5678 ) > new MongoDB \BSON \Timestamp (1233 , 5678 ));
17
+
18
+ ?>
19
+ ===DONE===
20
+ <?php exit (0 ); ?>
21
+ --EXPECTF--
22
+ bool(true)
23
+ bool(false)
24
+ bool(false)
25
+ bool(true)
26
+ bool(true)
27
+ bool(true)
28
+ bool(true)
29
+ ===DONE===
You can’t perform that action at this time.
0 commit comments