Skip to content

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

Closed

Description

@bendavies

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

Activity

  1. changed the title [-]`DateTimeImmutable::diff` differences on in 8.1.10 onwards[/-] [+]`DateTimeImmutable::diff` differences on in 8.1.10 onwards - timezone related.[/+] on Oct 10, 2022
  2. changed the title [-]`DateTimeImmutable::diff` differences on in 8.1.10 onwards - timezone related.[/-] [+]`DateTimeImmutable::diff` differences in 8.1.10 onwards - timezone related.[/+] on Oct 10, 2022
  3. hormus commented on Oct 13, 2022

    @hormus

    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

  4. added a commit that references this issue on Nov 30, 2022
    d021851
  5. derickr commented on Nov 30, 2022

    @derickr
    Member

    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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions