summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/date/lib/interval.c5
-rw-r--r--ext/date/lib/timelib.h4
-rw-r--r--ext/date/tests/bug77097.phpt33
3 files changed, 39 insertions, 3 deletions
diff --git a/ext/date/lib/interval.c b/ext/date/lib/interval.c
index e9fa274563..d1f7db107a 100644
--- a/ext/date/lib/interval.c
+++ b/ext/date/lib/interval.c
@@ -35,7 +35,10 @@ timelib_rel_time *timelib_diff(timelib_time *one, timelib_time *two)
rt = timelib_rel_time_ctor();
rt->invert = 0;
- if (one->sse > two->sse) {
+ if (
+ (one->sse > two->sse) ||
+ (one->sse == two->sse && one->us > two->us)
+ ) {
swp = two;
two = one;
one = swp;
diff --git a/ext/date/lib/timelib.h b/ext/date/lib/timelib.h
index e272cfcd13..537c75a695 100644
--- a/ext/date/lib/timelib.h
+++ b/ext/date/lib/timelib.h
@@ -322,8 +322,8 @@ typedef struct _timelib_tzdb {
#endif
#define TIMELIB_VERSION 201801
-#define TIMELIB_EXTENDED_VERSION 20180103
-#define TIMELIB_ASCII_VERSION "2018.01RC1"
+#define TIMELIB_EXTENDED_VERSION 20180104
+#define TIMELIB_ASCII_VERSION "2018.01RC2"
#define TIMELIB_NONE 0x00
#define TIMELIB_OVERRIDE_TIME 0x01
diff --git a/ext/date/tests/bug77097.phpt b/ext/date/tests/bug77097.phpt
new file mode 100644
index 0000000000..effaad4900
--- /dev/null
+++ b/ext/date/tests/bug77097.phpt
@@ -0,0 +1,33 @@
+--TEST--
+Bug #77097 (DateTime::diff gives wrong diff when the actual diff is less than 1 second)
+--FILE--
+<?php
+$now = new DateTime('2018-11-03 11:34:20.781751');
+$ago = new DateTime('2018-11-03 11:34:20.000000');
+
+$diff = $now->diff($ago);
+var_dump($diff->invert, $diff->s, $diff->f);
+
+$diff = $ago->diff($now);
+var_dump($diff->invert, $diff->s, $diff->f);
+
+$diff = $now->diff($ago, true);
+var_dump($diff->invert, $diff->s, $diff->f);
+
+$diff = $ago->diff($now, true);
+var_dump($diff->invert, $diff->s, $diff->f);
+?>
+--EXPECTF--
+int(1)
+int(0)
+float(0.781751)
+int(0)
+int(0)
+float(0.781751)
+int(0)
+int(0)
+float(0.781751)
+int(0)
+int(0)
+float(0.781751)
+