Bug->Doc #46670 [Opn->Ana]: date_sunrise (date_sunset) works incorrectly with gmtoffset parameter

From: Date: Mon, 12 Feb 2018 15:27:35 +0000
Subject: Bug->Doc #46670 [Opn->Ana]: date_sunrise (date_sunset) works incorrectly with gmtoffset parameter
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-15427@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=46670&edit=1 ID: 46670 Updated by: cmb@php.net Reported by: andrewboltachev at gmail dot com Summary: date_sunrise (date_sunset) works incorrectly with gmtoffset parameter -Status: Open +Status: Analyzed -Type: Bug +Type: Documentation Problem Package: Date/time related Operating System: UNIX PHP Version: 5.2.6 -Assigned To: +Assigned To: cmb Block user comment: N Private report: N New Comment: > […] 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. Previous Comments: ------------------------------------------------------------------------ [2018-01-26 19:15:44] 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. ------------------------------------------------------------------------ [2008-11-25 20:13:13] 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 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=46670&edit=1

« previous php.doc.bugs (#15427) next »