php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53148 date_sunrise and date_sunset show tomorrow's times for some timezones.
Submitted: 2010-10-25 03:44 UTC Modified: 2018-06-24 04:22 UTC
Votes:7
Avg. Score:4.3 ± 0.9
Reproduced:7 of 7 (100.0%)
Same Version:1 (14.3%)
Same OS:4 (57.1%)
From: sec at mboca dot com Assigned: cmb (profile)
Status: No Feedback Package: Date/time related
PHP Version: 5.2.14 and 5.3.3 OS: linux and windows
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
10 + 44 = ?
Subscribe to this entry?

 
 [2010-10-25 03:44 UTC] sec at mboca dot com
Description:
------------
when you try to get sunrise and sunset times from the area that have GMT +12 or over.  the sunrise and sunset times will be listed for next day.  
The sunrise and sunset times should be listed for today.  

http://weatherpixel.com/bug.php
the source code is at http://weatherpixel.com/bug.php?src=show

one of the examples that the Fiji Island times would only show for tomorrow and 
my script would show it as night as always. 
http://weatherpixel.com/sunrise_gmt.php?station=NFFN  



Here is my configure line for linux: 

./configure --enable-sockets --enable-calendar --with-curl=/usr/lib/ --with-gd --with-jpeg-dir=/usr/local/lib --with-png-dir=/usr/local/lib --with-ttf --enable-gd-native-ttf --with-gettext --with-freetype-dir=/usr/local/lib --without-sqlite --without-pdo-sqlite  --with-apxs2=/usr/local/apache2/bin/apxs




Test script:
---------------
here is php script that reproduce the date_sunrise
http://weatherpixel.com/bug.php?src=show



Expected result:
----------------
the times for +12 GMT and more than +12 GMT will always show tomorrow's sunrise and sunset times.  



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-10-28 06:32 UTC] sec at mboca dot com
This bug also happens on php 5.3.3 with same configure line in my post above.
 [2010-10-28 06:33 UTC] sec at mboca dot com
-PHP Version: 5.2.14 +PHP Version: 5.2.14 and 5.3.3
 [2010-10-28 06:33 UTC] sec at mboca dot com
It happens on php 5.3.3 too.
 [2010-10-31 10:32 UTC] sec at mboca dot com
-Package: Math related +Package: *Calendar problems
 [2010-10-31 10:32 UTC] sec at mboca dot com
I figured out a workaround to this bug. 
you have to add -1 day to subtract one day from sunrise and sunset times. 


if ($offset >= 12 && strcmp(date_default_timezone_get(), "Pacific/Tarawa") != 0) {
echo "+12 GMT workaround done<br>";
$sunrise = strtotime('-1 day', $sunrise);
$sunset = strtotime('-1 day', $sunset);
$csunrise = strtotime('-1 day', $csunrise);
$csunset = strtotime('-1 day', $csunset);
$nsunrise = strtotime('-1 day', $nsunrise);
$nsunset = strtotime('-1 day', $nsunset);
$asunrise = strtotime('-1 day', $asunrise);
$asunset = strtotime('-1 day', $asunset);
}

I need to test on time zones that are -12 in offsets 
might have to do +1 day on that offset.
 [2010-10-31 16:56 UTC] felipe@php.net
-Package: *Calendar problems +Package: Date/time related
 [2010-11-03 22:38 UTC] felipe@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: derick
 [2013-10-28 22:14 UTC] phpnet at stanton dot co dot nz
PHP 5.3.15 Also has this issue though I don't believe it is related to the timezone being +12 or over

Keeping the timezone the same I changed the longitude value from 175 to 180 in 0.25 increments and found the sunrise/set values jump to the next day at different longitudes according to the time of the year.


Checking for the sunrise time on Oct 1st 2013 10:35 (NZ summer time) at longitude 177.25 gets 2013-10-01T06:45:18+13:00 but shift the longitude to 177.5 at the sunrise is reported as 2013-10-02T06:44:18+13:00

Checking for the sunrise time on Oct 31st 2013 10:35 (NZ standard time) at longitude 175.75 gets 2013-10-31T06:09:32+13:00 but shift the longitude to 176 at the sunrise is reported as 2013-11-01T06:08:32+13:00
 [2017-10-24 07:52 UTC] kalle@php.net
-Status: Assigned +Status: Open -Assigned To: derick +Assigned To:
 [2018-02-12 18:01 UTC] cmb@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2018-02-12 18:01 UTC] cmb@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with ,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.
 [2018-06-24 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 [2019-11-21 20:33 UTC] gasparmdq at gmail dot com
The same problem happens on PHP7.3

A snippet of code that shows the issue could be:
<?php
        $dateTime = new DateTime('2013-10-01T10:35:00.000+13:00');
        $timestamp = $dateTime->getTimestamp();

        $sunInfo = date_sun_info($timestamp, -37.6908, 177.25);
        $sunInfo_2 = date_sun_info($timestamp, -37.6908, 177.50);

        echo $timestamp."<br>";

        echo "Sunrise for longitude 177.25: ".$sunInfo['sunrise']."<br>";
        echo "Sunrise for longitude 177.50: ".$sunInfo_2['sunrise']."<br>";
?>
which outputs:
1380576900
Sunrise for longitude 177.25: 1380476829
Sunrise for longitude 177.50: 1380563169


The sunrise for long 177.25, when transformed a readable value is:
GMT: Sunday, September 29, 2013 5:47:09 PM
Your time zone: Monday, September 30, 2013 6:47:09 AM GMT+13:00 DST

The sunrise for long 177.50, becomes:
GMT: Monday, September 30, 2013 5:46:09 PM
Your time zone: Tuesday, October 1, 2013 6:46:09 AM GMT+13:00 DST

As you can notice, the seed timestamp for both is the same, the only difference is the longitude value. But we still get results for the next day.

This was reproduced using the latest PHP7.3 docker image (using alpine linux), also can be reproduced copying the provided code on http://phpfiddle.org/ (I don't know what environment they use). 
This also happened on our old PHP5.6 servers using CentOS so it looks like is not OS/PHP version dependent, but an actual bug on the code.

Shall the behaviour exposed were intended, I would appreciate some sort of explanation regarding the why is expected.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 15:01:29 2024 UTC