Skip to content

Commit ae987ca

Browse files
committed
PHPC-654: UTCDateTime comparison handler
1 parent 7a12b86 commit ae987ca

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

src/BSON/UTCDateTime.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,20 @@ phongo_create_object_retval php_phongo_utcdatetime_create_object(zend_class_entr
487487
#endif
488488
} /* }}} */
489489

490+
static int php_phongo_utcdatetime_compare_objects(zval *o1, zval *o2 TSRMLS_DC) /* {{{ */
491+
{
492+
php_phongo_utcdatetime_t *intern1, *intern2;
493+
494+
intern1 = Z_UTCDATETIME_OBJ_P(o1);
495+
intern2 = Z_UTCDATETIME_OBJ_P(o2);
496+
497+
if (intern1->milliseconds != intern2->milliseconds) {
498+
return intern1->milliseconds < intern2->milliseconds ? -1 : 1;
499+
}
500+
501+
return 0;
502+
} /* }}} */
503+
490504
HashTable *php_phongo_utcdatetime_get_properties(zval *object TSRMLS_DC) /* {{{ */
491505
{
492506
php_phongo_utcdatetime_t *intern;
@@ -540,6 +554,7 @@ PHP_MINIT_FUNCTION(UTCDateTime)
540554
zend_class_implements(php_phongo_utcdatetime_ce TSRMLS_CC, 1, zend_ce_serializable);
541555

542556
memcpy(&php_phongo_handler_utcdatetime, phongo_get_std_object_handlers(), sizeof(zend_object_handlers));
557+
php_phongo_handler_utcdatetime.compare_objects = php_phongo_utcdatetime_compare_objects;
543558
php_phongo_handler_utcdatetime.get_properties = php_phongo_utcdatetime_get_properties;
544559
#if PHP_VERSION_ID >= 70000
545560
php_phongo_handler_utcdatetime.free_obj = php_phongo_utcdatetime_free_object;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
MongoDB\BSON\UTCDateTime comparisons
3+
--FILE--
4+
<?php
5+
6+
var_dump(new MongoDB\BSON\UTCDateTime(1234) == new MongoDB\BSON\UTCDateTime(1234));
7+
var_dump(new MongoDB\BSON\UTCDateTime(1234) < new MongoDB\BSON\UTCDateTime(1234));
8+
var_dump(new MongoDB\BSON\UTCDateTime(1234) > new MongoDB\BSON\UTCDateTime(1234));
9+
10+
var_dump(new MongoDB\BSON\UTCDateTime(1234) < new MongoDB\BSON\UTCDateTime(1235));
11+
var_dump(new MongoDB\BSON\UTCDateTime(1234) > new MongoDB\BSON\UTCDateTime(1233));
12+
13+
?>
14+
===DONE===
15+
<?php exit(0); ?>
16+
--EXPECTF--
17+
bool(true)
18+
bool(false)
19+
bool(false)
20+
bool(true)
21+
bool(true)
22+
===DONE===

0 commit comments

Comments
 (0)