Skip to content

Commit

Permalink
Fixed bug #77097 (DateTime::diff gives wrong diff when the actual dif…
Browse files Browse the repository at this point in the history
…f is less than 1 second) by upgrading to timelib 2017.09
  • Loading branch information
derickr committed Nov 28, 2018
1 parent 17f8b9f commit a3f2871
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 4 deletions.
4 changes: 4 additions & 0 deletions NEWS
Expand Up @@ -11,6 +11,10 @@ PHP NEWS
- COM:
. Fixed bug #77177 (Serializing or unserializing COM objects crashes). (cmb)

- Date:
. Fixed bug #77097 (DateTime::diff gives wrong diff when the actual diff is
less than 1 second). (Derick)

- Exif:
. Fixed bug #77184 (Unsigned rational numbers are written out as signed
rationals). (Colin Basnett)
Expand Down
5 changes: 4 additions & 1 deletion ext/date/lib/interval.c
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions ext/date/lib/timelib.h
Expand Up @@ -310,9 +310,9 @@ typedef struct _timelib_tzdb {
# define timelib_free free
#endif

#define TIMELIB_VERSION 201708
#define TIMELIB_EXTENDED_VERSION 20170800
#define TIMELIB_ASCII_VERSION "2017.08"
#define TIMELIB_VERSION 201709
#define TIMELIB_EXTENDED_VERSION 20170900
#define TIMELIB_ASCII_VERSION "2017.09"

#define TIMELIB_NONE 0x00
#define TIMELIB_OVERRIDE_TIME 0x01
Expand Down
33 changes: 33 additions & 0 deletions 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)

0 comments on commit a3f2871

Please sign in to comment.