Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fractions in diff() are not correctly normalized giving wrong values #50

Closed
ludesign opened this issue Oct 11, 2018 · 2 comments
Closed

Comments

@ludesign
Copy link

Description:

timelib_do_rel_normalize() does not normalize fractions by calling do_range_limit_fraction() resulting in incorrect DateInterval values.

Consider the dates: 2018-10-11 20:59:06.914653 and 2018-10-11 20:59:07.237419 they differ by 0.322766 seconds but diff() is reported as string(16) "00:00:01.-677234" when formatted via format('%H:%I:%S.%F')

Dump of DateInterval object:

class DateInterval#32 (16) {
  public $y =>
  int(0)
  public $m =>
  int(0)
  public $d =>
  int(0)
  public $h =>
  int(0)
  public $i =>
  int(0)
  public $s =>
  int(1)
  public $f =>
  double(-0.677234)
  public $weekday =>
  int(0)
  public $weekday_behavior =>
  int(0)
  public $first_last_day_of =>
  int(0)
  public $invert =>
  int(0)
  public $days =>
  int(0)
  public $special_type =>
  int(0)
  public $special_amount =>
  int(0)
  public $have_weekday_relative =>
  int(0)
  public $have_special_relative =>
  int(0)
}

Test script:

<?php
$startDate = new \DateTime('2018-10-11 20:59:06.914653');
$endDate  = new \DateTime('2018-10-11 20:59:07.237419');
$interval = $startDate->diff($endDate);
var_dump($interval->format('%H:%I:%S.%F'));

Expected result:

string(16) "00:00:00.322766"

Actual result:

string(16) "00:00:01.-677234"

@derickr
Copy link
Owner

derickr commented Oct 12, 2018

Thanks for this report, I've fixed this in timelib now. Is there a PHP bug for this too?

@derickr
Copy link
Owner

derickr commented Oct 12, 2018

I added one myself: https://bugs.php.net/bug.php?id=77007 — this is now fixed for PHP 7.2.12 and PHP 7.3.0RC4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants