php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #78267 Change in sun times result with PHP version change
Submitted: 2019-07-09 19:34 UTC Modified: 2019-07-13 15:33 UTC
From: stefano dot borghi at gmx dot com Assigned:
Status: Closed Package: Date/time related
PHP Version: 7.2.20 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: stefano dot borghi at gmx dot com
New email:
PHP Version: OS:

 

 [2019-07-09 19:34 UTC] stefano dot borghi at gmx dot com
Description:
------------
In PHP >= v7.2 the result of the `date_sun_info` function, and similarly the other sun related functions, return a different value for sunrise and sunset compared to the previous PHP versions.

I'm not sure if this is an expected change due to a correction of a previously wrong result or if it's an actual bug.

In any case this change is not reported in the documentation.


Test script:
---------------
// see https://3v4l.org/31aER

function sunTimes($lat, $long, $date)
{
    date_default_timezone_set('UTC');

    $sun_info = date_sun_info(strtotime($date),  $lat, $long);

    $sunrise = date("H:i:s", $sun_info['sunrise']);
    $sunset =  date("H:i:s", $sun_info['sunset']);

    return "on $date sun rises at $sunrise and sets at $sunset";
}

echo sunTimes(51.5, 0, '2018-03-14'); // ~London


Expected result:
----------------
// PHP <= v7.1.0
'on 2018-03-14 sun rises at 06:14:51 and sets at 18:03:16'  


Actual result:
--------------
// PHP >= v7.2.4
'on 2018-03-14 sun rises at 06:15:59 and sets at 18:02:24'


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-07-13 15:33 UTC] cmb@php.net
-Status: Open +Status: Verified
 [2019-07-13 15:33 UTC] cmb@php.net
This[1] has basically been a bug fix, since formerly the time to
calculate the Julian Day count has been adjusted to noon, albeit
the JD calculation already catered to that, which caused the
calculation to be half a day off.  For instance, in your example
the time was actually calculated for 2018-03-14.5 (i.e. a
hypothetical day between the 14th and 15th).  Now the time is
properly adjusted to midnight.

[1] <https://github.com/php/php-src/commit/a063d55395c818c401b7efdf6b42b4728ce3df08>
 [2019-07-13 15:33 UTC] cmb@php.net
-Type: Bug +Type: Documentation Problem
 [2020-01-09 13:29 UTC] contact at frank-liepert dot de
It seems like PHP 7.2 has fixed another issue when dealing with different timezones.


Test script:
------------

<?php

$longitude = 12.7645;
$latitude = 48.9825;

date_default_timezone_set('America/New_York');
$dateTime = new DateTime('2019-07-08');
$sunrise = date_sunrise($dateTime->getTimestamp(), SUNFUNCS_RET_TIMESTAMP, $latitude, $longitude, 90 + 5 / 6);
var_dump($sunrise);

date_default_timezone_set('UTC');
$dateTime = new DateTime('2019-07-08');
$sunrise = date_sunrise($dateTime->getTimestamp(), SUNFUNCS_RET_TIMESTAMP, $latitude, $longitude, 90 + 5 / 6);
var_dump($sunrise);

date_default_timezone_set('Australia/Brisbane');
$dateTime = new DateTime('2019-07-08');
$sunrise = date_sunrise($dateTime->getTimestamp(), SUNFUNCS_RET_TIMESTAMP, $latitude, $longitude, 90 + 5 / 6);
var_dump($sunrise);


Output for 7.2.0 - 7.4.1
------------------------
int(1562555526)
int(1562555526)
int(1562555526)


Output for 5.3.0 - 7.1.33
------------------------
int(1562555561)
int(1562555552)
int(1562555531)
 [2022-06-02 16:10 UTC] git@php.net
Automatic comment on behalf of derickr
Revision: https://github.com/php/doc-en/commit/d9ae294a02fa49a5d063dbcde2ca1f7e7a770c80
Log: Fixed bug #78267: Change in sun times result with PHP version change
 [2022-06-02 16:10 UTC] git@php.net
-Status: Verified +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 27 09:01:29 2024 UTC