php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #46670 date_sunrise (date_sunset) works incorrectly with gmtoffset parameter
Submitted: 2008-11-25 20:13 UTC Modified: 2018-02-12 17:20 UTC
Votes:8
Avg. Score:4.1 ± 0.8
Reproduced:7 of 7 (100.0%)
Same Version:2 (28.6%)
Same OS:2 (28.6%)
From: andrewboltachev at gmail dot com Assigned: cmb (profile)
Status: Closed Package: Date/time related
PHP Version: 5.2.6 OS: UNIX
Private report: No CVE-ID: None
 [2008-11-25 20:13 UTC] andrewboltachev at gmail dot com
Description:
------------
date_sunrise (date_sunset) incorrectly works with gmtoffset parameter. When i use SUNFUNCS_RET_TIMESTAMP, it ignores it and calculates date by adding UTC sunrise date and my location offset. When use SUNFUNCS_RET_STRING, all is ok. I don't checked SUNFUNCS_RET_DOUBLE.

Reproduce code:
---------------
<?php
$lat = 43.1167; $lng = 131.9; //Vladivostok, Russia, UTC+10

date_default_timezone_set('Europe/Moscow'); //My location timezone, UTC+3

$zenith = 90+50/60;



$offset = 10; //Vladivostok

$sunrise_str = date_sunrise(time(),SUNFUNCS_RET_STRING,$lat,$lng,$zenith,$offset);
$sunrise_time = date_sunrise (time(),SUNFUNCS_RET_TIMESTAMP,$lat,$lng,$zenith,$offset);
echo "By string : $sunrise_str, by timestamp: ".date("Y-m-d H:i:s",$sunrise_time)."<br/>\n";



$offset = 0; //UTC

$sunrise_str = date_sunrise(time(),SUNFUNCS_RET_STRING,$lat,$lng,$zenith,$offset);
$sunrise_time = date_sunrise (time(),SUNFUNCS_RET_TIMESTAMP,$lat,$lng,$zenith,$offset);
echo "By string : $sunrise_str, by timestamp: ".date("Y-m-d H:i:s",$sunrise_time)."<br/>\n";



$offset = 3; //UTC plus my timezone offset

$sunrise_str = date_sunrise(time(),SUNFUNCS_RET_STRING,$lat,$lng,$zenith,$offset);
$sunrise_time = date_sunrise (time(),SUNFUNCS_RET_TIMESTAMP,$lat,$lng,$zenith,$offset);
echo "By string : $sunrise_str, by timestamp: ".date("Y-m-d H:i:s",$sunrise_time)."<br/>\n";
?>

Expected result:
----------------
By string : 08:16, by timestamp: 2008-11-25 08:16:18
By string : 22:16, by timestamp: 2008-11-24 22:16:18
By string : 01:16, by timestamp: 2008-11-25 01:16:18

Actual result:
--------------
By string : 08:16, by timestamp: 2008-11-25 01:16:18
By string : 22:16, by timestamp: 2008-11-25 01:16:18
By string : 01:16, by timestamp: 2008-11-25 01:16:18

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-10-24 07:50 UTC] kalle@php.net
-Status: Assigned +Status: Open -Assigned To: derick +Assigned To:
 [2018-01-26 19:15 UTC] mattleff at gmail dot com
I am wondering if this is a documentation change, since the code appears to intentionally ignore the offset for SUNFUNCS_RET_TIMESTAMP:

https://github.com/php/php-src/blob/master/ext/date/php_date.c#L4916-L4919

Otherwise this would be a trivial fix.
 [2018-02-12 15:27 UTC] cmb@php.net
-Status: Open +Status: Analyzed -Type: Bug +Type: Documentation Problem -Assigned To: +Assigned To: cmb
 [2018-02-12 15:27 UTC] cmb@php.net
> […] since the code appears to intentionally ignore the offset
> for SUNFUNCS_RET_TIMESTAMP:

Indeed, and that is quite logical since UNIX timestamps are always
UTC, so applying any offset would be wrong.
 [2018-02-12 17:19 UTC] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=344245
Log: Fix bug #46670: date_sunrise (date_sunset) works incorrectly with gmtoffset parameter
 [2018-02-12 17:20 UTC] cmb@php.net
-Status: Analyzed +Status: Closed
 [2018-02-12 17:20 UTC] cmb@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.
 [2020-02-07 06:05 UTC] phpdocbot@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=6b897704a1d3378833a84781ab8a272bd8546ffb
Log: Fix bug #46670: date_sunrise (date_sunset) works incorrectly with gmtoffset parameter
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 17:01:29 2024 UTC