php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #67870 jdtounix() claims localtime, but that's not true
Submitted: 2014-08-20 09:14 UTC Modified: 2017-09-04 12:03 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: asphp at dsgml dot com Assigned: cmb (profile)
Status: Closed Package: Calendar related
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: asphp at dsgml dot com
New email:
PHP Version: OS:

 

 [2014-08-20 09:14 UTC] asphp at dsgml dot com
Description:
------------
---
From manual page: http://www.php.net/function.jdtounix
---

It says: "The time returned is localtime (and not GMT)."

But this is not true.

Part of the problem is bug #13187 which claims:

"so jdtounix returns localtime while
mysql unix_timestamp returns GMT"

Which is not true! It's actually exactly the opposite! MySQL returns localtime, and PHP returns GMT.

You can even look at the source code:

(uday * 24 * 3600)

No adjustment whatsoever for timezone.

Test script:
---------------
<?
date_default_timezone_set('America/New_York');
echo jdtounix(2440588) , "\n" . jdtounix(2440589);


Expected result:
----------------
If it was local time then I would not get:

0
86400

But I do. Those times are exactly midnight UTC.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-08-20 09:16 UTC] asphp at dsgml dot com
And just to really confuse everyone, unixtojd() IS localtime, but doesn't say so in the documentation!

Source code:

if (!(ta = php_localtime_r(&ts, &tmbuf))) {
 [2014-10-23 07:26 UTC] saeed at hubaishan dot com
you can test this by:
<?php
echo (jdtounix(rand(2440588,2465342))%86400) //always 0
?>
 [2017-01-28 17:12 UTC] cmb@php.net
-Package: Documentation problem +Package: Calendar related
 [2017-09-04 11:41 UTC] cmb@php.net
-Status: Open +Status: Verified -Assigned To: +Assigned To: cmb
 [2017-09-04 11:41 UTC] cmb@php.net
> MySQL returns localtime, and PHP returns GMT.

Well, actually PHP returns UTC, but indeed not local time. Thanks!
 [2017-09-04 12:03 UTC] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=342998
Log: Fix bug #67870 (jdtounix() claims localtime, but that's not true)
 [2017-09-04 12:03 UTC] cmb@php.net
-Status: Verified +Status: Closed
 [2020-02-07 06:06 UTC] phpdocbot@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=b92b86af557c40f9af69a8c4d1f2fbf1c5c39f92
Log: Fix bug #67870 (jdtounix() claims localtime, but that's not true)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 27 12:01:29 2024 UTC