php / php/php-src

Evalute U-timestamp in createFromFormat as GMT timestamp

Open
#16,277 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Extension: date Status: Needs Triage
Dominant language
C
Stars
40.4k
Forks
8.1k
Avg merge
2d 13h
Merged PRs (30d)
96

Description

Description

The following code:

<?php
echo DateTime::createFromFormat('U e', '1730597400 America/Toronto')->format('U');

Resulted in this output:

1730615400

It's 5 hours more than the input timestamp.

But I expected this output instead:

1730597400

The difference matches the timezone offset.

But documentation on createFromFormat about U says:

Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)

GMT is specified, so I expect the timestamp to be constant whatever is the timezone.

I.E. I expect DateTime::createFromFormat('U e', '1730597400 America/Toronto') to be equivalent to:

$date = DateTime::createFromFormat('U', '1730597400');
$date->setTimezone(new DateTimeZone('America/Toronto'));
PHP Version

PHP 8.3.12

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the DateTime::createFromFormat('U e', ...) example from the issue and compare it with the documented GMT behavior for U. Trace the createFromFormat entry point and determine whether the implementation or documentation needs adjustment; done means the reported timezone-offset discrepancy is resolved and covered by verification.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.