com php-src: Test + support for negative timestamps with microtime: ext/date/php_date.c ext/date/tests/bug68078_n egative.phpt
| From: | Derick Rethans | Date: | Fri, 29 Jan 2016 14:22:22 +0000 |
| Subject: | com php-src: Test + support for negative timestamps with microtime: ext/date/php_date.c ext/date/tests/bug68078_n egative.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-90800@lists.php.net to get a copy of this message | ||
Commit: 2aeef4e5390344115391607792dbf8b94b3ec459
Author: Willem-Jan <wjzijderveld@gmail.com> Mon, 30 Nov 2015 17:35:12 +0100
Committer: Derick Rethans <github@derickrethans.nl> Fri, 29 Jan 2016 15:22:22 +0100
Parents: 1bbbc47e796ca562095f3e8c419f35b031f687d3
Branches: PHP-5.6 PHP-7.0 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=2aeef4e5390344115391607792dbf8b94b3ec459
Log:
Test + support for negative timestamps with microtime
Changed paths:
M ext/date/php_date.c
A ext/date/tests/bug68078_negative.phpt
Diff:
diff --git a/ext/date/php_date.c b/ext/date/php_date.c
index 45e77c3..4ef9547 100644
--- a/ext/date/php_date.c
+++ b/ext/date/php_date.c
@@ -2201,7 +2201,11 @@ static int date_object_compare_date(zval *d1, zval *d2 TSRMLS_DC)
return 0;
}
- return (o1->time->f < o2->time->f) ? -1 : 1;
+ if (o1->time->sse < 0) {
+ return (o1->time->f < o2->time->f) ? 1 : -1;
+ } else {
+ return (o1->time->f < o2->time->f) ? -1 : 1;
+ }
}
return (o1->time->sse < o2->time->sse) ? -1 : 1;
diff --git a/ext/date/tests/bug68078_negative.phpt b/ext/date/tests/bug68078_negative.phpt
new file mode 100644
index 0000000..93b7715
--- /dev/null
+++ b/ext/date/tests/bug68078_negative.phpt
@@ -0,0 +1,19 @@
+--TEST--
+Comparing datetime objects with negative timestamps should account for microseconds
+--FILE--
+<?php
+
+date_default_timezone_set('UTC');
+$earlyDate1 = DateTime::createFromFormat('U.u', '1.8642')->modify('-5
seconds');
+$earlyDate2 = DateTime::createFromFormat('U.u', '1.2768')->modify('-5
seconds');
+$earlyDate3 = DateTime::createFromFormat('U.u', '1.2768')->modify('-5
seconds');
+
+var_dump($earlyDate1 == $earlyDate2);
+var_dump($earlyDate1 < $earlyDate2);
+var_dump($earlyDate2 > $earlyDate1);
+var_dump($earlyDate2 == $earlyDate3);
+--EXPECT--
+bool(false)
+bool(true)
+bool(true)
+bool(true)