Skip to content

DateTime modify with unixtimestamp (@) must work like setTimestamp #9891

Closed
@goncons

Description

@goncons

Description

The following code:

<?php
$a = new DateTime('2022-11-01 13:30:00', new DateTimezone('America/Lima'));
$b = clone $a;
echo '$a: ', $a->format(DateTime::ATOM), "\r\n";
echo '$b: ', $b->format(DateTime::ATOM), "\r\n";
echo '$a: @', $a->getTimestamp(), "\r\n";
echo '$b: setTimestamp(', $b->getTimestamp(), ")\r\n";
$a->modify('@' . $a->getTimestamp());
$b->setTimestamp($b->getTimestamp());
echo '$a: ', $a->format(DateTime::ATOM), "\r\n";
echo '$b: ', $b->format(DateTime::ATOM), "\r\n";

Resulted in this output:

$a: 2022-11-01T13:30:00-05:00
$b: 2022-11-01T13:30:00-05:00
$a: @1667327400
$b: setTimestamp(1667327400)
$a: 2022-11-01T18:30:00-05:00
$b: 2022-11-01T13:30:00-05:00

But I expected this output instead:

$a: 2022-11-01T13:30:00-05:00
$b: 2022-11-01T13:30:00-05:00
$a: @1667327400
$b: setTimestamp(1667327400)
$a: 2022-11-01T13:30:00-05:00
$b: 2022-11-01T13:30:00-05:00

PHP Version

PHP 8.1.12

Operating System

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions