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

DateTimeImmutable::diff differences in 8.1.10 onwards - timezone related. #9699

Closed
bendavies opened this issue Oct 10, 2022 · 2 comments
Closed

Comments

@bendavies
Copy link

bendavies commented Oct 10, 2022

Description

The following code:

<?php

$date = new DateTimeImmutable('2022-10-09 02:41:54.515330', new DateTimeZone('America/Los_Angeles'));
$now = new DateTimeImmutable('2022-10-10 08:41:54.534620', new DateTimeZone('UTC'));

var_dump($date->diff($now));

Resulted in this output:

object(DateInterval)#3 (16) {
  ["y"]=>
  int(-1)
  ["m"]=>
  int(11)
  ["d"]=>
  int(30)
  ["h"]=>
  int(0)
  ["i"]=>
  int(59)
  ["s"]=>
  int(59)
  ["f"]=>
  float(0.98071)
  ["weekday"]=>
  int(0)
  ["weekday_behavior"]=>
  int(0)
  ["first_last_day_of"]=>
  int(0)
  ["invert"]=>
  int(1)
  ["days"]=>
  int(0)
  ["special_type"]=>
  int(0)
  ["special_amount"]=>
  int(0)
  ["have_weekday_relative"]=>
  int(0)
  ["have_special_relative"]=>
  int(0)
}

But I expected this output instead:

object(DateInterval)#3 (16) {
  ["y"]=>
  int(0)
  ["m"]=>
  int(0)
  ["d"]=>
  int(0)
  ["h"]=>
  int(23)
  ["i"]=>
  int(0)
  ["s"]=>
  int(0)
  ["f"]=>
  float(0.01929)
  ["weekday"]=>
  int(0)
  ["weekday_behavior"]=>
  int(0)
  ["first_last_day_of"]=>
  int(0)
  ["invert"]=>
  int(0)
  ["days"]=>
  int(0)
  ["special_type"]=>
  int(0)
  ["special_amount"]=>
  int(0)
  ["have_weekday_relative"]=>
  int(0)
  ["have_special_relative"]=>
  int(0)
}

https://3v4l.org/Jam7q

PHP Version

8.1.10

Operating System

No response

@bendavies bendavies changed the title DateTimeImmutable::diff differences on in 8.1.10 onwards DateTimeImmutable::diff differences on in 8.1.10 onwards - timezone related. Oct 10, 2022
@bendavies bendavies changed the title DateTimeImmutable::diff differences on in 8.1.10 onwards - timezone related. DateTimeImmutable::diff differences in 8.1.10 onwards - timezone related. Oct 10, 2022
@hormus
Copy link

hormus commented Oct 13, 2022

America/Los_angeles: 2022 dom 13 mar, 2.00 PST → PDT +1 hour (DST start) UTC-7
Problem of documentation: change From 8.1.0 diff convert from local "America/Los_angeles" 2022-10-09 02:41:54.515330 to "UTC local from America/Los_angeles" 2022-10-09 02:41:54.515330. Previous or PHP >= 8.1.10

//If the timezones are not the same, use
absolute(floor(($one->unixTime - $two->unixTime) / 86400))

"UTC" 2022-10-09 09:41:54.515330
@derickr The change creates more breaks than advantages. Please restore 23 hours if timezone != same type. (Never 23 hours is one day for != timezone convert with timezone $originObject and $targetObject UTC).
PHP >= 8.1.10 Timezone same type https://bugs.php.net/bug.php?id=81458

@derickr
Copy link
Member

derickr commented Nov 30, 2022

Now fixed, for PHP 8.1.14 and PHP 8.2.1.

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

No branches or pull requests

5 participants
@derickr @bendavies @cmb69 @hormus and others