php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80145 date_sunrise / date_sunset skip a day in specific case
Submitted: 2020-09-24 11:47 UTC Modified: 2020-09-24 14:34 UTC
From: craigpvmts at gmail dot com Assigned:
Status: Verified Package: Date/time related
PHP Version: 7.4.10 OS: Raspian 10 (Buster - Debian)
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2020-09-24 11:47 UTC] 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. 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-09-24 14:34 UTC] cmb@php.net
-Status: Open +Status: Verified
 [2020-09-24 14:34 UTC] 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>
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Fri Jan 22 04:01:23 2021 UTC