Bug #80145 [Ver->Wfx]: date_sunrise / date_sunset skip a day in specific case

From: Date: Fri, 13 May 2022 15:53:57 +0000
Subject: Bug #80145 [Ver->Wfx]: date_sunrise / date_sunset skip a day in specific case
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-241509@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80145&edit=1

 ID:                 80145
 Updated by:         derick@php.net
 Reported by:        craigpvmts at gmail dot com
 Summary:            date_sunrise / date_sunset skip a day in specific
                     case
-Status:             Verified
+Status:             Wont fix
 Type:               Bug
 Package:            Date/time related
 Operating System:   Raspian 10 (Buster - Debian)
 PHP Version:        7.4.10
 Block user comment: N
 Private report:     N

 New Comment:

The date_sunrise function got deprecated with PHP 8.1. If this still happens with the replacement
sun_info() function, please file a new ticket at https://github.com/php/php-src/issues.


Previous Comments:
------------------------------------------------------------------------
[2020-09-24 14:34:39] cmb@php.net

Simpler reproducer: <https://3v4l.org/ZEg9Q>.

This is almost certainly a timelib[1] issue, and might have been
introduced with commit 8d0066f66[2].

[1] <https://github.com/derickr/timelib>
[2] <https://github.com/derickr/timelib/commit/8d0066f7110d4b8bd1a745bc6628c34577c34ba5>

------------------------------------------------------------------------
[2020-09-24 11:47:19] craigpvmts at gmail dot com

Description:
------------
Hi all,

I wrote some php code that operates & logs data on a solar PV system. It makes use of
date_sunrise / date_sunset methods to determine approximately when the system should be active. The
system failed to start today because the next sunrise time was off by 24h. After evaluating the code
and writing a short script, confirmed that the date_sunrise / date_sunset functions appear to skip a
day at midnight Sept 23-24, 2020 - at least when given lat/long coordinates in New Zealand when the
local machine is set to NZST (UTC+12). When given a time after Sept 24th, the returned
sunrise/sunset times will be 1 day in the future.

Attaching sample code to reproduce the issue.

Thanks for any update.

Test script:
---------------
#!/usr/bin/php
<?php

$today=1600776000;	// 2020-09-23 00:00:00 NZST (= 2020-09-22 12:00:00 UTC)
$i=0;
while ($i<=72)
{
	print($today." ".date('Y-m-d H:i:s',$today)." Rise:".
	date_sunrise($today,SUNFUNCS_RET_TIMESTAMP,-38.6623,178.0176)." Set:".
	date_sunset($today,SUNFUNCS_RET_TIMESTAMP,-38.6623,178.0176).
	"\n");
	++$i;
	$today+=3600;
}
?>


Expected result:
----------------
Test code should generate a list of 72 entries by hour. Every 24 entries the Rise/Set values for
sunrise/sunset should increment by roughly 86400 (1 day in seconds).  I'm not actually clear on
exactly when this method is expected to increment the date - it appears to depend on the current
timezone setting (or perhaps solar midnight at the lat/long?). Regardless, at local (NZST) midnight
on Sept 23/24 the returned values increment by 2 days. Here is a sample line from the output on Sept
23 when run in New Zealand Standard Time that works as expected:

1600819200 2020-09-23 12:00:00 Rise:1600797323 Set:1600841112



Actual result:
--------------
Here is a portion of the result for 4 key points in time when run on a Raspberry Pi set to New
Zealand Standard Time:

1600819200 2020-09-23 12:00:00 Rise:1600797323 Set:1600841112
1600858800 2020-09-23 23:00:00 Rise:1600797323 Set:1600841112
1600862400 2020-09-24 00:00:00 Rise:1600970027 Set:1601013966
1600905600 2020-09-24 12:00:00 Rise:1600970027 Set:1601013966

Lines 1 and 2 are correct / expected, lines 3 and 4 are incorrect - Rise and Set values should be
about 86400 (1 day) lower. 


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=80145&edit=1


Thread (3 messages)

« previous php.bugs (#241509) next »